Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow creating server without editing generated code #276

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions example/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"github.com/hooklift/gowsdl/soap"
)

//go:generate go run ../cmd/gowsdl -p gen -o gen.go ../fixtures/stock.wsdl

func ExampleBasicUsage() {
client := soap.NewClient("http://svc.asmx")
service := gen.NewStockQuotePortType(client)
Expand Down
31 changes: 25 additions & 6 deletions example/gen/gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

204 changes: 204 additions & 0 deletions example/gen/servergen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 13 additions & 1 deletion example/server/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"github.com/hooklift/gowsdl/soap"
)

//go:generate go run ../../cmd/gowsdl -p gen ../../fixtures/test.wsdl

var done = make(chan struct{})

func client() {
Expand All @@ -21,9 +23,19 @@ func client() {
done <- struct{}{}
}

type server struct {
*gen.BaseSOAPService
}

func (s server) GetInfoFunc(request *gen.GetInfo) (*gen.GetInfoResponse, error) {
return &gen.GetInfoResponse{
GetInfoResult: "gowsdl, " + request.Id,
}, nil
}

// use fixtures/test.wsdl
func main() {
http.HandleFunc("/", gen.Endpoint)
http.HandleFunc("/", gen.CreateEndpoint(&server{}))
go func() {
time.Sleep(time.Second * 1)
client()
Expand Down
31 changes: 31 additions & 0 deletions example/server/example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package main

import (
"net/http/httptest"
"testing"

"github.com/hooklift/gowsdl/example/server/gen"
"github.com/hooklift/gowsdl/soap"
)

func TestExampleServer(t *testing.T) {
httpServer := httptest.NewServer(gen.CreateEndpoint(&server{}))
t.Cleanup(httpServer.Close)

httpClient := httpServer.Client()
soapClient := soap.NewClient(httpServer.URL, soap.WithHTTPClient(httpClient))
service := gen.NewMNBArfolyamServiceType(soapClient)

id := "veryrandomid"
resp, err := service.GetInfoSoap(&gen.GetInfo{
Id: id,
})
if err != nil {
t.Fatal(err)
}

expected := "gowsdl, " + id
if resp.GetInfoResult != expected {
t.Fatalf("got %s, want %s", resp.GetInfoResult, expected)
}
}
25 changes: 23 additions & 2 deletions example/server/gen/myservice.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading