client

package
v1.54.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 21, 2025 License: MIT Imports: 5 Imported by: 0

README

Package client

Пакет client предоставляет SOAP-клиент для взаимодействия с SOAP-сервисами. Поддерживает отправку запросов, обработку ответов и ошибок в формате SOAP Fault.

Types

Client

Структура для отправки SOAP-запросов. Использует httpcli.Client для HTTP-взаимодействия.

Methods:

New(cli *httpcli.Client) Client

Конструктор клиента.

(c Client) Invoke(ctx context.Context, url string, soapAction string, extraHeaders map[string]string, requestBody any) (*Response, error)

Отправляет SOAP-запрос. Автоматически формирует SOAP-конверт.

Usage

Default usage flow
package main

import (
	"context"
	"encoding/xml"
	"log"

	"github.com/txix-open/isp-kit/http/httpclix"
	"github.com/txix-open/isp-kit/http/soap/client"
)

type userRequest struct {
	XMLName xml.Name `xml:"UserRequest"`
	Name    string   `xml:"name"`
}

type userResponse struct {
	XMLName xml.Name `xml:"UserResponse"`
	Id      int      `xml:"id"`
}

func main() {
	cli := client.New(httpclix.Default())
	resp, err := cli.Invoke(
		context.Background(),
		"https://api.example.com/users",
		"CreateUser",
		nil,
		userRequest{Name: "Alice"},
	)
	if err != nil {
		log.Fatal(err)
	}
	defer resp.Close()

	var res userResponse
	err = resp.UnmarshalPayload(&res)
	if err == nil {
		log.Printf("id: %d\n", res.Id)
		return
	}

	fault, err := resp.Fault()
	if err != nil {
		log.Fatal(err)
	}
	log.Printf("SOAP Fault: %s\n", fault.String)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func New

func New(cli *httpcli.Client) Client

func (Client) Invoke

func (c Client) Invoke(
	ctx context.Context,
	url string,
	soapAction string,
	extraHeaders map[string]string,
	requestBody any,
) (*Response, error)

type PlainXml

type PlainXml struct {
	Value []byte `xml:",innerxml"`
}

type Response

type Response struct {
	Http *httpcli.Response
}

func (*Response) Close

func (r *Response) Close()

func (*Response) Fault

func (r *Response) Fault() (*soap.Fault, error)

func (*Response) UnmarshalPayload

func (r *Response) UnmarshalPayload(responseBody any) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL