Skip to content

Commit 8413716

Browse files
committed
basic auth added
1 parent 02ee328 commit 8413716

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

generator/operations_tmpl.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ var opsTmpl = `
1010
client *gowsdl.SoapClient
1111
}
1212
13-
func New{{$portType}}(url string, tls bool) *{{$portType}} {
13+
func New{{$portType}}(url string, tls bool, auth *gowsdl.BasicAuth) *{{$portType}} {
1414
if url == "" {
1515
url = {{findServiceAddress .Name | printf "%q"}}
1616
}
17-
client := gowsdl.NewSoapClient(url, tls)
17+
client := gowsdl.NewSoapClient(url, tls, auth)
1818
1919
return &{{$portType}}{
2020
client: client,

generator/soap.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"net/http"
1212

1313
"gopkg.in/inconshreveable/log15.v2"
14+
"fmt"
1415
)
1516

1617
var Log = log15.New()
@@ -41,19 +42,26 @@ type SoapFault struct {
4142
Detail string `xml:"detail,omitempty"`
4243
}
4344

45+
type BasicAuth struct {
46+
Login string
47+
Password string
48+
}
49+
4450
type SoapClient struct {
4551
url string
4652
tls bool
53+
auth *BasicAuth
4754
}
4855

4956
func (f *SoapFault) Error() string {
5057
return f.Faultstring
5158
}
5259

53-
func NewSoapClient(url string, tls bool) *SoapClient {
60+
func NewSoapClient(url string, tls bool, auth *BasicAuth) *SoapClient {
5461
return &SoapClient{
5562
url: url,
5663
tls: tls,
64+
auth: auth,
5765
}
5866
}
5967

@@ -85,6 +93,9 @@ func (s *SoapClient) Call(soapAction string, request, response interface{}) erro
8593
}
8694

8795
req, err := http.NewRequest("POST", s.url, buffer)
96+
if s.auth != nil {
97+
req.SetBasicAuth(s.auth.Login, s.auth.Password)
98+
}
8899
req.Header.Add("Content-Type", "text/xml; charset=\"utf-8\"")
89100
if soapAction != "" {
90101
req.Header.Add("SOAPAction", soapAction)
@@ -111,7 +122,7 @@ func (s *SoapClient) Call(soapAction string, request, response interface{}) erro
111122
Log.Warn("empty response")
112123
return nil
113124
}
114-
125+
fmt.Println(string(rawbody))
115126
respEnvelope := &SoapEnvelope{}
116127

117128
err = xml.Unmarshal(rawbody, respEnvelope)

0 commit comments

Comments
 (0)