From 6c304d3559a463468718757d5af3dc5049b59b88 Mon Sep 17 00:00:00 2001 From: Tiago Temporin Date: Fri, 16 Jun 2017 07:18:51 -0300 Subject: [PATCH] change example to README --- README.md | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ example_test.go | 43 ------------------------------------------- 2 files changed, 48 insertions(+), 43 deletions(-) delete mode 100644 example_test.go diff --git a/README.md b/README.md index 773b709..2fce9fa 100644 --- a/README.md +++ b/README.md @@ -5,4 +5,52 @@ package to help with SOAP integrations (client) ```bash go get github.com/tiaguinho/gosoap +``` + +### Example + +```go +package main + +import ( + "github.com/tiaguinho/gosoap" + "fmt" +) + +type GetGeoIPResponse struct { + GetGeoIPResult GetGeoIPResult +} + +type GetGeoIPResult struct { + ReturnCode string + IP string + ReturnCodeDetails string + CountryName string + CountryCode string +} + +var ( + r GetGeoIPResponse +) + +func main() { + soap, err := gosoap.SoapClient("http://www.webservicex.net/geoipservice.asmx?WSDL") + if err != nil { + fmt.Errorf("error not expected: %s", err) + } + + params := gosoap.Params{ + "IPAddress": "8.8.8.8", + } + + err = soap.Call("GetGeoIP", params) + if err != nil { + fmt.Errorf("error in soap call: %s", err) + } + + soap.Unmarshal(&r) + if r.GetGeoIPResult.CountryCode != "USA" { + fmt.Errorf("error: %+v", r) + } +} ``` \ No newline at end of file diff --git a/example_test.go b/example_test.go deleted file mode 100644 index c35bb30..0000000 --- a/example_test.go +++ /dev/null @@ -1,43 +0,0 @@ -package gosoap_test - -import ( - "github.com/tiaguinho/gosoap" - "testing" -) - -type GetGeoIPResponse struct { - GetGeoIPResult GetGeoIPResult -} - -type GetGeoIPResult struct { - ReturnCode string - IP string - ReturnCodeDetails string - CountryName string - CountryCode string -} - -var ( - r GetGeoIPResponse -) - -func TestClient_Call(t *testing.T) { - soap, err := gosoap.SoapClient("http://www.webservicex.net/geoipservice.asmx?WSDL") - if err != nil { - t.Errorf("error not expected: %s", err) - } - - params := gosoap.Params{ - "IPAddress": "8.8.8.8", - } - - err = soap.Call("GetGeoIP", params) - if err != nil { - t.Errorf("error in soap call: %s", err) - } - - soap.Unmarshal(&r) - if r.GetGeoIPResult.CountryCode != "USA" { - t.Errorf("error: %+v", r) - } -}