Skip to content

Instantly share code, notes, and snippets.

@braulio94
Last active August 21, 2019 19:15
Show Gist options
  • Save braulio94/11728bac45ebb6b79a3bc6c759a24f79 to your computer and use it in GitHub Desktop.
Save braulio94/11728bac45ebb6b79a3bc6c759a24f79 to your computer and use it in GitHub Desktop.
a go SOAP client that consumes a Holiday WebService
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)
}
@braulio94
Copy link
Author

WebService available here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment