Last active
August 21, 2019 19:15
-
-
Save braulio94/11728bac45ebb6b79a3bc6c759a24f79 to your computer and use it in GitHub Desktop.
a go SOAP client that consumes a Holiday WebService
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/xml" | |
"fmt" | |
"github.com/tiaguinho/gosoap" | |
"log" | |
) | |
type GetHolidaysForMonthResponse struct { | |
XMLName xml.Name `xml:"GetHolidaysForMonthResponse"` | |
GetHolidayMonthResult GetHolidayMonthResult `xml:"GetHolidaysForMonthResult"` | |
} | |
type GetHolidayMonthResult struct { | |
XMLName xml.Name `xml:"GetHolidaysForMonthResult"` | |
Holiday []Holiday `xml:"Holiday"` | |
} | |
type Holiday struct { | |
Country string `xml:"Country"` | |
HolidayCode string `xml:"HolidayCode"` | |
Descriptor string `xml:"Descriptor"` | |
HolidayType string `xml:"HolidayType"` | |
DateType string `xml:"DateType"` | |
BankHoliday string `xml:"BankHoliday"` | |
Date string `xml:"Date"` | |
} | |
var ( | |
response GetHolidaysForMonthResponse | |
) | |
func main(){ | |
soap, err := gosoap.SoapClient("http://www.holidaywebservice.com//HolidayService_v2/HolidayService2.asmx?wsdl") | |
if err != nil { | |
log.Fatalf("SoapClient error: %s", err) | |
} | |
params := gosoap.Params{ | |
"countryCode": "UnitedStates", | |
"year": "2019", | |
"month": "12", | |
} | |
res, err := soap.Call("GetHolidaysForMonth", params) | |
if err != nil { | |
log.Fatalf("Call error: %s", err) | |
} | |
fmt.Println("RESPONSE: ", &res) | |
err = xml.Unmarshal(res.Body, &response) | |
if err != nil { | |
log.Fatalf("xml.Unmarshal error: %s", err) | |
} | |
fmt.Println("GOT THE RESPONSE: ", response.GetHolidayMonthResult.Holiday) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
WebService available here