gosoap

package module
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2019 License: MIT Imports: 14 Imported by: 0

README

Go Soap Build Status GoDoc Go Report Card codecov patreon

package to help with SOAP integrations (client)

Install
go get github.com/highercomve/gosoap
Example
package main

import (
	"encoding/xml"
	"log"

	"github.com/highercomve/gosoap"
)

// GetIPLocationResponse will hold the Soap response
type GetIPLocationResponse struct {
	GetIPLocationResult string `xml:"GetIpLocationResult"`
}

// GetIPLocationResult will
type GetIPLocationResult struct {
	XMLName xml.Name `xml:"GeoIP"`
	Country string   `xml:"Country"`
	State   string   `xml:"State"`
}

var (
	r GetIPLocationResponse
)

func main() {
	soap, err := gosoap.SoapClient("http://wsgeoip.lavasoft.com/ipservice.asmx?WSDL")
	if err != nil {
		log.Fatalf("SoapClient error: %s", err)
	}

	params := gosoap.Params{
		"sIp": "8.8.8.8",
	}

	res, err := soap.Call("GetIpLocation", params)
	if err != nil {
		log.Fatalf("Call error: %s", err)
	}

	res.Unmarshal(&r)

	// GetIpLocationResult will be a string. We need to parse it to XML
	result := GetIPLocationResult{}
	err = xml.Unmarshal([]byte(r.GetIPLocationResult), &result)
	if err != nil {
		log.Fatalf("xml.Unmarshal error: %s", err)
	}

	if result.Country != "US" {
		log.Fatalf("error: %+v", r)
	}

	log.Println("Country: ", result.Country)
	log.Println("State: ", result.State)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetPayloadFromError added in v1.4.0

func GetPayloadFromError(err error) []byte

GetPayloadFromError returns the payload of a ErrorWithPayload

Types

type Client

type Client struct {
	HTTPClient   *http.Client
	URL          string
	HeaderName   string
	HeaderParams HeaderParams
	Definitions  *wsdlDefinitions
	// Must be set before first request otherwise has no effect, minimum is 15 minutes.
	RefreshDefinitionsAfter time.Duration
	Username                string
	Password                string
	// contains filtered or unexported fields
}

Client struct hold all the informations about WSDL, request and response of the server

func SoapClient

func SoapClient(wsdl string, httpClient *http.Client) (*Client, error)

SoapClient return new *Client to handle the requests with the WSDL

func (*Client) Call

func (c *Client) Call(m string, p Params) (res *Response, err error)

Call call's the method m with Params p

func (*Client) CallByStruct added in v1.4.0

func (c *Client) CallByStruct(s RequestStruct) (res *Response, err error)

CallByStruct call's by struct

func (*Client) Do added in v1.4.0

func (c *Client) Do(req *Request) (res *Response, err error)

Do Process Soap Request

func (*Client) SetWSDL added in v1.4.0

func (c *Client) SetWSDL(wsdl string)

SetWSDL set WSDL url

type ErrorWithPayload added in v1.4.0

type ErrorWithPayload struct {
	Payload []byte
	// contains filtered or unexported fields
}

ErrorWithPayload error payload schema

type Fault added in v1.1.0

type Fault struct {
	Code        string `xml:"faultcode"`
	Description string `xml:"faultstring"`
	Detail      string `xml:"detail"`
}

Fault response

type HeaderParams added in v1.2.0

type HeaderParams map[string]interface{}

HeaderParams holds params specific to the header

type Params

type Params map[string]interface{}

Params type is used to set the params in soap request

type Request added in v1.4.0

type Request struct {
	Method string
	Params Params
}

Request Soap Request

func NewRequest added in v1.4.0

func NewRequest(m string, p Params) *Request

NewRequest creates a new soap request

func NewRequestByStruct added in v1.4.0

func NewRequestByStruct(s RequestStruct) (*Request, error)

NewRequestByStruct create a new request using builder

type RequestStruct added in v1.4.0

type RequestStruct interface {
	SoapBuildRequest() *Request
}

RequestStruct soap request interface

type Response added in v1.4.0

type Response struct {
	Body    []byte
	Header  []byte
	Payload []byte
}

Response Soap Response

func (*Response) Unmarshal added in v1.4.0

func (r *Response) Unmarshal(v interface{}) error

Unmarshal get the body and unmarshal into the interface

type SoapBody

type SoapBody struct {
	XMLName  struct{} `xml:"Body"`
	Contents []byte   `xml:",innerxml"`
}

SoapBody struct

type SoapEnvelope

type SoapEnvelope struct {
	XMLName struct{} `xml:"Envelope"`
	Header  SoapHeader
	Body    SoapBody
}

SoapEnvelope struct

type SoapHeader added in v1.2.0

type SoapHeader struct {
	XMLName  struct{} `xml:"Header"`
	Contents []byte   `xml:",innerxml"`
}

SoapHeader struct

Jump to

Keyboard shortcuts

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