-
Notifications
You must be signed in to change notification settings - Fork 13
/
client.go
57 lines (49 loc) · 1.83 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package soap
import (
"context"
"errors"
"net/http"
)
var (
// ErrInvalidPEMFileSpecified is returned if the PEM file specified for WS signing is invalid
ErrInvalidPEMFileSpecified = errors.New("invalid PEM key specified")
// ErrEncryptedPEMFileSpecified is returnedd if the PEM file specified for WS signing is encrypted
ErrEncryptedPEMFileSpecified = errors.New("encrypted PEM key specified")
// ErrUnsupportedContentType is returned if we encounter a non-supported content type while querying
ErrUnsupportedContentType = errors.New("unsupported content-type in response")
)
// Client is an opaque handle to a SOAP service.
type Client struct {
http *http.Client
}
// NewClient creates a new Client that will access a SOAP service.
// Requests made using this client will all be wrapped in a SOAP envelope.
// See https://www.w3schools.com/xml/xml_soap.asp for more details.
// The default HTTP client used has no timeout nor circuit breaking. Override with SettHTTPClient. You have been warned.
func NewClient(http *http.Client) *Client {
return &Client{
http: http,
}
}
// Do invokes the SOAP request using its internal parameters.
// The request argument is serialized to XML, and if the call is successful the received XML
// is deserialized into the response argument.
// Any errors that are encountered are returned.
// If a SOAP fault is detected, then the 'details' property of the SOAP envelope will be deserialized into the faultDetailType argument.
func (c *Client) Do(ctx context.Context, req *Request) (*Response, error) {
httpReq, err := req.httpRequest()
if err != nil {
return nil, err
}
httpResp, err := c.http.Do(httpReq.WithContext(ctx))
if err != nil {
return nil, err
}
defer httpResp.Body.Close()
resp := newResponse(httpResp, req)
err = resp.deserialize()
if err != nil {
return nil, err
}
return resp, nil
}