Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: hooklift/gowsdl
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: Telmate/gowsdl
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 12 commits
  • 9 files changed
  • 2 contributors

Commits on Feb 1, 2019

  1. Add context to Call() signature

    This allows to configure a timeout per call as opposed to a global
    timeout that's currently supported. This is a breaking change.
    iszak committed Feb 1, 2019
    Copy the full SHA
    9f5ceb6 View commit details
  2. Updated tests

    iszak committed Feb 1, 2019
    Copy the full SHA
    0ef471c View commit details
  3. Drop support for Golang < 1.10

    This is because they are not supported by the release policy.
    iszak committed Feb 1, 2019
    Copy the full SHA
    ac769a6 View commit details
  4. Use strings for Go versions

    YAML sees these as numbers so 1.10 is seen as 1.1 which is not the
    version we want to target.
    iszak committed Feb 1, 2019
    Copy the full SHA
    199b101 View commit details
  5. include ctx parameters in WSDL template outputs

    Grant Gongaware committed Feb 1, 2019
    Copy the full SHA
    38f8dbf View commit details
  6. Copy the full SHA
    847558e View commit details
  7. include context in interface

    Grant Gongaware committed Feb 1, 2019
    Copy the full SHA
    7c809e9 View commit details
  8. is there a better way to this?

    Grant Gongaware committed Feb 1, 2019
    Copy the full SHA
    b938713 View commit details

Commits on Jun 17, 2021

  1. support optional http keep-alive

    Grant Gongaware committed Jun 17, 2021
    Copy the full SHA
    53bc862 View commit details

Commits on Dec 3, 2021

  1. Hack around go install paths

    Grant Gongaware committed Dec 3, 2021
    Copy the full SHA
    bf581ef View commit details
  2. use the matching repo reference

    Grant Gongaware committed Dec 3, 2021
    Copy the full SHA
    cb210bf View commit details

Commits on Mar 1, 2023

  1. Copy the full SHA
    5cdb2b0 View commit details
Showing with 74 additions and 42 deletions.
  1. +3 −3 .travis.yml
  2. +1 −1 cmd/gowsdl/main.go
  3. +2 −2 example/example.go
  4. +3 −2 example/gen/gen.go
  5. +1 −1 go.mod
  6. +1 −0 header_tmpl.go
  7. +3 −3 operations_tmpl.go
  8. +57 −28 soap/soap.go
  9. +3 −2 soap/soap_test.go
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
language: go

go:
- 1.4
- 1.5
- tip
- "1.10"
- "1.11"
- "tip"

matrix:
allow_failures:
2 changes: 1 addition & 1 deletion cmd/gowsdl/main.go
Original file line number Diff line number Diff line change
@@ -54,7 +54,7 @@ import (
"log"
"os"

gen "github.com/hooklift/gowsdl"
gen "github.com/telmate/gowsdl"
)

// Version is initialized in compilation time by go build.
4 changes: 2 additions & 2 deletions example/example.go
Original file line number Diff line number Diff line change
@@ -5,8 +5,8 @@ import (
"log"
"time"

"github.com/hooklift/gowsdl/example/gen"
"github.com/hooklift/gowsdl/soap"
"github.com/telmate/gowsdl/example/gen"
"github.com/telmate/gowsdl/soap"
)

func ExampleBasicUsage() {
5 changes: 3 additions & 2 deletions example/gen/gen.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package gen

import (
"context"
"encoding/xml"
"time"

"github.com/hooklift/gowsdl/soap"
"github.com/telmate/gowsdl/soap"
)

// against "unused imports"
@@ -39,7 +40,7 @@ func NewStockQuotePortType(client *soap.Client) StockQuotePortType {

func (service *stockQuotePortType) GetLastTradePrice(request *TradePriceRequest) (*TradePrice, error) {
response := new(TradePrice)
err := service.client.Call("http://example.com/GetLastTradePrice", request, response)
err := service.client.Call(context.Background(), "http://example.com/GetLastTradePrice", request, response)
if err != nil {
return nil, err
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module github.com/hooklift/gowsdl
module github.com/telmate/gowsdl
1 change: 1 addition & 0 deletions header_tmpl.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions operations_tmpl.go
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ var opsTmpl = `
// {{range .Faults}}
// - {{.Name}} {{.Doc}}{{end}}{{end}}
{{if ne .Doc ""}}/* {{.Doc}} */{{end}}
{{makePublic .Name | replaceReservedWords}} ({{if ne $requestType ""}}request *{{$requestType}}{{end}}) (*{{$responseType}}, error)
{{makePublic .Name | replaceReservedWords}} (ctx context.Context, {{if ne $requestType ""}}request *{{$requestType}}{{end}}) (*{{$responseType}}, error)
{{/*end*/}}
{{end}}
}
@@ -41,9 +41,9 @@ var opsTmpl = `
{{$requestType := findType .Input.Message | replaceReservedWords | makePublic}}
{{$soapAction := findSOAPAction .Name $privateType}}
{{$responseType := findType .Output.Message | replaceReservedWords | makePublic}}
func (service *{{$privateType}}) {{makePublic .Name | replaceReservedWords}} ({{if ne $requestType ""}}request *{{$requestType}}{{end}}) (*{{$responseType}}, error) {
func (service *{{$privateType}}) {{makePublic .Name | replaceReservedWords}} (ctx context.Context, {{if ne $requestType ""}}request *{{$requestType}}{{end}}) (*{{$responseType}}, error) {
response := new({{$responseType}})
err := service.client.Call("{{$soapAction}}", {{if ne $requestType ""}}request{{else}}nil{{end}}, response)
err := service.client.Call(ctx, "{{$soapAction}}", {{if ne $requestType ""}}request{{else}}nil{{end}}, response)
if err != nil {
return nil, err
}
85 changes: 57 additions & 28 deletions soap/soap.go
Original file line number Diff line number Diff line change
@@ -2,8 +2,10 @@ package soap

import (
"bytes"
"context"
"crypto/tls"
"encoding/xml"
"fmt"
"io/ioutil"
"net"
"net/http"
@@ -23,6 +25,15 @@ type SOAPBody struct {
Content interface{} `xml:",omitempty"`
}

type Error struct {
Err error
Req *http.Request
Res *http.Response
}

func (e *Error) Unwrap() error { return e.Err }
func (e *Error) Error() string { return fmt.Sprintf("Soap Error: %s", e.Err) }

// UnmarshalXML unmarshals SOAPBody xml
func (b *SOAPBody) UnmarshalXML(d *xml.Decoder, _ xml.StartElement) error {
if b.Content == nil {
@@ -144,18 +155,20 @@ type basicAuth struct {
}

type options struct {
tlsCfg *tls.Config
auth *basicAuth
timeout time.Duration
contimeout time.Duration
tlsCfg *tls.Config
auth *basicAuth
timeout time.Duration
contimeout time.Duration
tlshshaketimeout time.Duration
httpHeaders map[string]string
keepalive bool
httpHeaders map[string]string
}

var defaultOptions = options{
timeout: time.Duration(30 * time.Second),
contimeout: time.Duration(90*time.Second),
tlshshaketimeout: time.Duration(15*time.Second),
keepalive: true,
timeout: time.Duration(30 * time.Second),
contimeout: time.Duration(90 * time.Second),
tlshshaketimeout: time.Duration(15 * time.Second),
}

// A Option sets options such as credentials, tls, etc.
@@ -168,7 +181,6 @@ func WithTLSHandshakeTimeout(t time.Duration) Option {
}
}


// WithRequestTimeout is an Option to set default end-end connection timeout
func WithRequestTimeout(t time.Duration) Option {
return func(o *options) {
@@ -197,18 +209,31 @@ func WithTimeout(t time.Duration) Option {
}
}

// WithKeepalive is an Option to set global HTTP headers for all requests
func WithKeepalive(keepalive bool) Option {
return func(o *options) {
o.keepalive = keepalive
}
}

// WithHTTPHeaders is an Option to set global HTTP headers for all requests
func WithHTTPHeaders(headers map[string]string) Option {
return func(o *options) {
o.httpHeaders = headers
}
}

// HTTPClient - mockable interface
type HTTPClient interface {
Do(req *http.Request) (*http.Response, error)
}

// Client is soap client
type Client struct {
url string
opts *options
headers []interface{}
HClient HTTPClient
}

// NewClient creates new SOAP client instance
@@ -217,9 +242,20 @@ func NewClient(url string, opt ...Option) *Client {
for _, o := range opt {
o(&opts)
}

tr := &http.Transport{
TLSClientConfig: opts.tlsCfg,
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
d := net.Dialer{Timeout: opts.timeout}
return d.DialContext(ctx, network, addr)
},
TLSHandshakeTimeout: opts.tlshshaketimeout,
}

return &Client{
url: url,
opts: &opts,
url: url,
opts: &opts,
HClient: &http.Client{Timeout: opts.contimeout, Transport: tr},
}
}

@@ -229,7 +265,7 @@ func (s *Client) AddHeader(header interface{}) {
}

// Call performs HTTP POST request
func (s *Client) Call(soapAction string, request, response interface{}) error {
func (s *Client) Call(ctx context.Context, soapAction string, request, response interface{}) error {
envelope := SOAPEnvelope{}

if s.headers != nil && len(s.headers) > 0 {
@@ -251,12 +287,13 @@ func (s *Client) Call(soapAction string, request, response interface{}) error {

req, err := http.NewRequest("POST", s.url, buffer)
if err != nil {
return err
return &Error{err, req, nil}
}
if s.opts.auth != nil {
req.SetBasicAuth(s.opts.auth.Login, s.opts.auth.Password)
}

req = req.WithContext(ctx)
req.Header.Add("Content-Type", "text/xml; charset=\"utf-8\"")
req.Header.Add("SOAPAction", soapAction)
req.Header.Set("User-Agent", "gowsdl/0.1")
@@ -265,41 +302,33 @@ func (s *Client) Call(soapAction string, request, response interface{}) error {
req.Header.Set(k, v)
}
}
req.Close = true

tr := &http.Transport{
TLSClientConfig: s.opts.tlsCfg,
Dial: func(network, addr string) (net.Conn, error) {
return net.DialTimeout(network, addr, s.opts.timeout)
},
TLSHandshakeTimeout: s.opts.tlshshaketimeout,
}
req.Close = !s.opts.keepalive

client := &http.Client{Timeout: s.opts.contimeout,Transport: tr,}
res, err := client.Do(req)
res, err := s.HClient.Do(req)
if err != nil {
return err
return &Error{err, req, res}
}
defer res.Body.Close()

rawbody, err := ioutil.ReadAll(res.Body)
if err != nil {
return err
return &Error{err, req, res}
}
if len(rawbody) == 0 {
return nil
return &Error{nil, req, res}
}

respEnvelope := new(SOAPEnvelope)
respEnvelope.Body = SOAPBody{Content: response}
err = xml.Unmarshal(rawbody, respEnvelope)
if err != nil {
return err
return &Error{err, req, res}
}

fault := respEnvelope.Body.Fault
if fault != nil {
return fault
return &Error{fault, req, res}
}

return nil
5 changes: 3 additions & 2 deletions soap/soap_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package soap

import (
"context"
"encoding/xml"
"net/http"
"net/http/httptest"
@@ -52,7 +53,7 @@ func TestClient_Call(t *testing.T) {
client := NewClient(ts.URL)
req := &Ping{Request: &PingRequest{Message: "Hi"}}
reply := &PingResponse{}
if err := client.Call("GetData", req, reply); err != nil {
if err := client.Call(context.Background(), "GetData", req, reply); err != nil {
t.Fatalf("couln't call service: %v", err)
}

@@ -105,7 +106,7 @@ func TestClient_Send_Correct_Headers(t *testing.T) {
client := NewClient(ts.URL, WithHTTPHeaders(test.reqHeaders))
req := struct{}{}
reply := struct{}{}
client.Call(test.action, req, reply)
client.Call(context.Background(), test.action, req, reply)

for k, v := range test.expectedHeaders {
h := gotHeaders.Get(k)