Skip to content
forked from globusdigital/soap

Adaptation of "github.com/globusdigital/soap" to operate with PromoStandards API

License

Notifications You must be signed in to change notification settings

j-low/promosoap

 
 

Repository files navigation

PromoSOAP

This is an adaptation of GlobusDigital's SOAP package for Go, featuring small updates to integrate with PromoStandards APIs.

Service

package main

import (
	"encoding/xml"
	"fmt"
	"net/http"

	"github.com/j-low/promosoap"
)

// FooRequest a simple request
type FooRequest struct {
	XMLName xml.Name `xml:"fooRequest"`
	Foo     string
}

// FooResponse a simple response
type FooResponse struct {
	Bar string
}

// RunServer run a little demo server
func RunServer() {
	soapServer := soap.NewServer()
	soapServer.HandleOperation(
		// SOAPAction
		"operationFoo",
		// tagname of soap body content
		"fooRequest",
		// RequestFactoryFunc - give the server sth. to unmarshal the request into
		func() interface{} {
			return &FooRequest{}
		},
		// OperationHandlerFunc - do something
		func(request interface{}, w http.ResponseWriter, httpRequest *http.Request) (response interface{}, err error) {
			fooRequest := request.(*FooRequest)
			fooResponse := &FooResponse{
				Bar: "Hello " + fooRequest.Foo,
			}
			response = fooResponse
			return
		},
	)
	err := soapServer.ListenAndServe(":8080")
	fmt.Println("exiting with error", err)
}

func main() {
	RunServer()
}

Client

package main

import (
	"encoding/xml"
	"log"

	"github.com/j-low/promosoap"
)

// FooRequest a simple request
type FooRequest struct {
	XMLName xml.Name `xml:"fooRequest"`
	Foo     string
}

// FooResponse a simple response
type FooResponse struct {
	Bar string
}

func main() {
	client := soap.NewClient("http://127.0.0.1:8080/", nil)
	response := &FooResponse{}
	httpResponse, err := client.Call("operationFoo", &FooRequest{Foo: "hello i am foo"}, response)
	if err != nil {
		panic(err)
	}
	log.Println(response.Bar, httpResponse.Status)
}

Apache License Version 2.0

About

Adaptation of "github.com/globusdigital/soap" to operate with PromoStandards API

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%