soap

package module
v0.0.0-...-90178bc Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2019 License: MIT Imports: 9 Imported by: 0

README

SOAP Go Client

Install

go get -u github.com/itcomusic/soap

Usage

package main

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

	"github.com/itcomusic/soap"
)

// <urn:ExampleRequest xmlns:urn="something">
//    <Attr>Go</Attr>
// </urn:ExampleRequest>

type Request struct {
	XMLName xml.Name `xml:"urn:ExampleRequest"`
	XmlNS   string   `xml:"xmlns:urn,attr"`
	Attr    string   `xml:"Attr"`
}

func main() {
	c := soap.NewClient("http://127.0.0.1/call", soap.Config{
		BasicAuth: &soap.BasicAuth{
			Username: "test",
			Password: "test",
		},
		TLS: &tls.Config{InsecureSkipVerify: true}})
	
    ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
    defer cancel()
	if err := c.Call(ctx, "", Request{
		XmlNS: "something",
		Attr:  "Go",
	}, nil); err != nil {
		log.Fatal(err)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicAuth

type BasicAuth struct {
	Username string
	Password string
}

BasicAuth implements work with basic authorization.

type Body

type Body struct {
	XMLName xml.Name    `xml:"http://schemas.xmlsoap.org/soap/envelope/ Body"`
	Fault   *Fault      `xml:",omitempty"`
	Content interface{} `xml:",omitempty"`
}

Body implements soap body.

func (*Body) UnmarshalXML

func (b *Body) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML implements xml.Unmarshaler interface.

type Client

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

Client implements soap client.

func NewClient

func NewClient(url string, c Config) *Client

NewClient creates soap client.

func (*Client) AddHeader

func (s *Client) AddHeader(header interface{})

AddHeader adds header.

func (*Client) Call

func (s *Client) Call(ctx context.Context, soapAction string, request, response interface{}) error

Call sends soap request.

type Config

type Config struct {
	BasicAuth           *BasicAuth
	TLS                 *tls.Config
	MaxIdleConnsPerHost int
}

Config implements config of the soap client.

type Envelope

type Envelope struct {
	XMLName xml.Name `xml:"http://schemas.xmlsoap.org/soap/envelope/ Envelope"`
	Header  *Header
	Body    Body
}

Envelope implements soap envelope.

type Fault

type Fault struct {
	XMLName    xml.Name  `xml:"http://schemas.xmlsoap.org/soap/envelope/ Fault"`
	Code       trimSpace `xml:"faultcode,omitempty"`
	Text       trimSpace `xml:"faultstring,omitempty"`
	Actor      trimSpace `xml:"faultactor,omitempty"`
	Detail     trimSpace `xml:"detail,omitempty"`
	HTTPStatus int       `xml:"-"`
}

Fault implements soap fault.

func (*Fault) Error

func (f *Fault) Error() string
type Header struct {
	XMLName xml.Name      `xml:"http://schemas.xmlsoap.org/soap/envelope/ Header"`
	Items   []interface{} `xml:",omitempty"`
}

Header implements soap headers.

Jump to

Keyboard shortcuts

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