diff --git a/Makefile b/Makefile index 06c2992..4545628 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,7 @@ build.debug: ## === Tools === -EXAMPLES=basic errors nullable multi +EXAMPLES=basic errors nullable union define examples .PHONY: example.$(1) example.$(1): diff --git a/example/basic/main.go b/example/basic/main.go index 6569fe6..051ea43 100644 --- a/example/basic/main.go +++ b/example/basic/main.go @@ -28,5 +28,5 @@ func main() { _ = exec.Command("open", "http://127.0.0.1:3000").Run() }() - _ = http.ListenAndServe("localhost:3000", mux) + panic(http.ListenAndServe("localhost:3000", mux)) } diff --git a/example/errors/call/main.go b/example/errors/call/main.go deleted file mode 100644 index 1d4ffef..0000000 --- a/example/errors/call/main.go +++ /dev/null @@ -1,167 +0,0 @@ -package main - -import ( - "context" - "fmt" - - "github.com/pkg/errors" - - "github.com/foomo/gotsrpc/v2" - "github.com/foomo/gotsrpc/v2/example/errors/handler/backend" - backendsvs "github.com/foomo/gotsrpc/v2/example/errors/service/backend" -) - -func main() { - ctx := context.Background() - c := backendsvs.NewDefaultServiceGoTSRPCClient("http://localhost:3000") - - { - fmt.Println("-------------------------") - var gotsrpcErr *gotsrpc.Error - serviceErr, err := c.Error(ctx) - if err != nil { - panic("client error should be nil") - } else if serviceErr == nil { - panic("service error should not be nil") - } else if serviceErr != nil { - fmt.Println("OK") - } - if errors.As(serviceErr, &gotsrpcErr) { - fmt.Printf("%s\n", gotsrpcErr) - fmt.Printf("%q\n", gotsrpcErr) - fmt.Printf("%+v\n", gotsrpcErr) - } - } - - { - fmt.Println("-------------------------") - scalar, err := c.Scalar(ctx) - if err != nil { - panic("client error should be nil") - } else if scalar == nil { - panic("service error should not be nil") - } else if scalar != nil { - fmt.Println("OK") - } - } - { - fmt.Println("-------------------------") - scalar, err := c.MultiScalar(ctx) - if err != nil { - panic("client error should be nil") - } else if scalar == nil { - panic("service error should not be nil") - } else if scalar != nil { - fmt.Println("OK") - } - } - - { - fmt.Println("-------------------------") - var gotsrpcErr *gotsrpc.Error - serviceErr, err := c.WrappedError(ctx) - if err != nil { - panic("client error should be nil") - } else if serviceErr == nil { - panic("service error should not be nil") - } else if serviceErr != nil { - fmt.Println("OK") - } - if errors.As(serviceErr, &gotsrpcErr) { - fmt.Println(gotsrpcErr.Error()) - fmt.Printf("%+v\n", gotsrpcErr) - } - if errors.As(errors.Unwrap(serviceErr), &gotsrpcErr) { - fmt.Println(gotsrpcErr.Error()) - } - } - - { - fmt.Println("-------------------------") - var scalarErr *backend.ScalarError - var gotsrpcErr *gotsrpc.Error - serviceErr, err := c.ScalarError(ctx) - if err != nil { - panic("client error should be nil") - } else if serviceErr == nil { - panic("service error should not be nil") - } else if serviceErr != nil { - fmt.Printf("%s\n", serviceErr) - fmt.Printf("%q\n", serviceErr) - fmt.Printf("%+v\n", serviceErr) - } - if errors.As(serviceErr, &gotsrpcErr) { - fmt.Println(gotsrpcErr) - } - if errors.As(serviceErr, &scalarErr) { - fmt.Println(scalarErr) - } - } - - { - fmt.Println("-------------------------") - var customErr *backend.CustomError - var gotsrpcErr *gotsrpc.Error - serviceErr, err := c.CustomError(ctx) - if err != nil { - panic("client error should be nil") - } else if serviceErr == nil { - panic("service error should not be nil") - } else if serviceErr != nil { - fmt.Printf("%s\n", serviceErr) - fmt.Printf("%q\n", serviceErr) - fmt.Printf("%+v\n", serviceErr) - } - if errors.As(serviceErr, &gotsrpcErr) { - fmt.Println(gotsrpcErr) - } - if errors.As(serviceErr, &customErr) { - fmt.Println(customErr) - } - } - - { - fmt.Println("-------------------------") - serviceErr, err := c.TypedError(ctx) - if err != nil { - panic("client error should be nil") - } else if serviceErr == nil { - panic("service error should not be nil") - } else if serviceErr != nil { - fmt.Println("OK") - } - if errors.Is(serviceErr, backend.ErrTyped) { - fmt.Println("OK") - } - } - - { - fmt.Println("-------------------------") - serviceErr, err := c.TypedWrappedError(ctx) - if err != nil { - panic("client error should be nil") - } else if serviceErr == nil { - panic("service error should not be nil") - } else if serviceErr != nil { - fmt.Println("OK") - } - if errors.Is(serviceErr, backend.ErrTyped) { - fmt.Println("OK") - } - } - - { - fmt.Println("-------------------------") - serviceErr, err := c.TypedCustomError(ctx) - if err != nil { - panic("client error should be nil") - } else if serviceErr == nil { - panic("service error should not be nil") - } else if serviceErr != nil { - fmt.Println("OK") - } - if errors.Is(serviceErr, backend.ErrCustom) { - fmt.Println("OK") - } - } -} diff --git a/example/errors/handler/frontend/handler.go b/example/errors/handler/frontend/handler.go index 534a583..e6ce3b9 100644 --- a/example/errors/handler/frontend/handler.go +++ b/example/errors/handler/frontend/handler.go @@ -23,7 +23,7 @@ func (h *Handler) Simple(w http.ResponseWriter, r *http.Request) (e *frontend.Er func (h *Handler) Multiple(w http.ResponseWriter, r *http.Request) (e *frontend.ErrMulti) { return &frontend.ErrMulti{ - ErrMultiA: frontend.ErrMultiAOne, - ErrMultiB: "", + A: frontend.ErrMultiAOne, + B: "", } } diff --git a/example/errors/main.go b/example/errors/main.go index 6007fdd..7e8d36f 100644 --- a/example/errors/main.go +++ b/example/errors/main.go @@ -1,11 +1,16 @@ package main import ( + "context" + "fmt" "net/http" "os/exec" "strings" "time" + "github.com/pkg/errors" + + "github.com/foomo/gotsrpc/v2" "github.com/foomo/gotsrpc/v2/example/errors/handler/backend" "github.com/foomo/gotsrpc/v2/example/errors/handler/frontend" backendsvs "github.com/foomo/gotsrpc/v2/example/errors/service/backend" @@ -32,11 +37,163 @@ func main() { go func() { time.Sleep(time.Second) _ = exec.Command("open", "http://127.0.0.1:3000").Run() + call() }() - go func() { - if err := http.ListenAndServe("localhost:3000", mux); err != nil { - panic(err) - } - }() + panic(http.ListenAndServe("localhost:3000", mux)) +} + +func call() { + ctx := context.Background() + c := backendsvs.NewDefaultServiceGoTSRPCClient("http://localhost:3000") + + { + fmt.Println("-------------------------") + var gotsrpcErr *gotsrpc.Error + serviceErr, err := c.Error(ctx) + if err != nil { + panic("client error should be nil") + } else if serviceErr == nil { + panic("service error should not be nil") + } else if serviceErr != nil { + fmt.Println("OK") + } + if errors.As(serviceErr, &gotsrpcErr) { + fmt.Printf("%s\n", gotsrpcErr) + fmt.Printf("%q\n", gotsrpcErr) + fmt.Printf("%+v\n", gotsrpcErr) + } + } + + { + fmt.Println("-------------------------") + scalar, err := c.Scalar(ctx) + if err != nil { + panic("client error should be nil") + } else if scalar == nil { + panic("service error should not be nil") + } else if scalar != nil { + fmt.Println("OK") + } + } + { + fmt.Println("-------------------------") + scalar, err := c.MultiScalar(ctx) + if err != nil { + panic("client error should be nil") + } else if scalar == nil { + panic("service error should not be nil") + } else if scalar != nil { + fmt.Println("OK") + } + } + + { + fmt.Println("-------------------------") + var gotsrpcErr *gotsrpc.Error + serviceErr, err := c.WrappedError(ctx) + if err != nil { + panic("client error should be nil") + } else if serviceErr == nil { + panic("service error should not be nil") + } else if serviceErr != nil { + fmt.Println("OK") + } + if errors.As(serviceErr, &gotsrpcErr) { + fmt.Println(gotsrpcErr.Error()) + fmt.Printf("%+v\n", gotsrpcErr) + } + if errors.As(errors.Unwrap(serviceErr), &gotsrpcErr) { + fmt.Println(gotsrpcErr.Error()) + } + } + + { + fmt.Println("-------------------------") + var scalarErr *backend.ScalarError + var gotsrpcErr *gotsrpc.Error + serviceErr, err := c.ScalarError(ctx) + if err != nil { + panic("client error should be nil") + } else if serviceErr == nil { + panic("service error should not be nil") + } else if serviceErr != nil { + fmt.Printf("%s\n", serviceErr) + fmt.Printf("%q\n", serviceErr) + fmt.Printf("%+v\n", serviceErr) + } + if errors.As(serviceErr, &gotsrpcErr) { + fmt.Println(gotsrpcErr) + } + if errors.As(serviceErr, &scalarErr) { + fmt.Println(scalarErr) + } + } + + { + fmt.Println("-------------------------") + var customErr *backend.CustomError + var gotsrpcErr *gotsrpc.Error + serviceErr, err := c.CustomError(ctx) + if err != nil { + panic("client error should be nil") + } else if serviceErr == nil { + panic("service error should not be nil") + } else if serviceErr != nil { + fmt.Printf("%s\n", serviceErr) + fmt.Printf("%q\n", serviceErr) + fmt.Printf("%+v\n", serviceErr) + } + if errors.As(serviceErr, &gotsrpcErr) { + fmt.Println(gotsrpcErr) + } + if errors.As(serviceErr, &customErr) { + fmt.Println(customErr) + } + } + + { + fmt.Println("-------------------------") + serviceErr, err := c.TypedError(ctx) + if err != nil { + panic("client error should be nil") + } else if serviceErr == nil { + panic("service error should not be nil") + } else if serviceErr != nil { + fmt.Println("OK") + } + if errors.Is(serviceErr, backend.ErrTyped) { + fmt.Println("OK") + } + } + + { + fmt.Println("-------------------------") + serviceErr, err := c.TypedWrappedError(ctx) + if err != nil { + panic("client error should be nil") + } else if serviceErr == nil { + panic("service error should not be nil") + } else if serviceErr != nil { + fmt.Println("OK") + } + if errors.Is(serviceErr, backend.ErrTyped) { + fmt.Println("OK") + } + } + + { + fmt.Println("-------------------------") + serviceErr, err := c.TypedCustomError(ctx) + if err != nil { + panic("client error should be nil") + } else if serviceErr == nil { + panic("service error should not be nil") + } else if serviceErr != nil { + fmt.Println("OK") + } + if errors.Is(serviceErr, backend.ErrCustom) { + fmt.Println("OK") + } + } } diff --git a/example/errors/service/frontend/vo.go b/example/errors/service/frontend/vo.go index 94890bf..9ac53c6 100644 --- a/example/errors/service/frontend/vo.go +++ b/example/errors/service/frontend/vo.go @@ -4,8 +4,8 @@ type ErrSimple string type ( ErrMulti struct { - A ErrMultiA `json:"a,union"` - B ErrMultiB `json:"b,union"` + A ErrMultiA `json:"a,omitempty,union"` + B ErrMultiB `json:"b,omitempty,union"` } ErrMultiA string ErrMultiB string diff --git a/example/multi/client/src/service-vo.ts b/example/multi/client/src/service-vo.ts deleted file mode 100644 index 2bd95fa..0000000 --- a/example/multi/client/src/service-vo.ts +++ /dev/null @@ -1,59 +0,0 @@ -/* eslint:disable */ -// hello commonjs - we need some imports - sorted in alphabetical order, by go package -import * as github_com_foomo_gotsrpc_v2_example_multi_service from './service-vo'; // ./client/src/service-vo.ts to ./client/src/service-vo.ts -// github.com/foomo/gotsrpc/v2/example/multi/service.InlineStruct -export interface InlineStruct extends github_com_foomo_gotsrpc_v2_example_multi_service.InlineStructA , github_com_foomo_gotsrpc_v2_example_multi_service.InlineStructB { - value:string; -} -// github.com/foomo/gotsrpc/v2/example/multi/service.InlineStructA -export interface InlineStructA { - valueA:string; -} -// github.com/foomo/gotsrpc/v2/example/multi/service.InlineStructB -export interface InlineStructB { - valueB:string; -} -// github.com/foomo/gotsrpc/v2/example/multi/service.InlineStructPtr -export interface InlineStructPtr extends Partial , Partial { - bug?:github_com_foomo_gotsrpc_v2_example_multi_service.InlineStructB; - value:string; -} -// github.com/foomo/gotsrpc/v2/example/multi/service.UnionString -export type UnionString = (typeof github_com_foomo_gotsrpc_v2_example_multi_service.UnionStringA) & (typeof github_com_foomo_gotsrpc_v2_example_multi_service.UnionStringB) -// github.com/foomo/gotsrpc/v2/example/multi/service.UnionStringA -export enum UnionStringA { - One = "one", - Two = "two", -} -// github.com/foomo/gotsrpc/v2/example/multi/service.UnionStringB -export enum UnionStringB { - Four = "four", - Three = "three", -} -// github.com/foomo/gotsrpc/v2/example/multi/service.UnionStruct -export type UnionStruct = github_com_foomo_gotsrpc_v2_example_multi_service.UnionStructA | github_com_foomo_gotsrpc_v2_example_multi_service.UnionStructB | undefined -// github.com/foomo/gotsrpc/v2/example/multi/service.UnionStructA -export interface UnionStructA { - kind:'UnionStructA'; - value:github_com_foomo_gotsrpc_v2_example_multi_service.UnionStructAValueA; - bar:string; -} -// github.com/foomo/gotsrpc/v2/example/multi/service.UnionStructAValueA -export enum UnionStructAValueA { - One = "one", - Three = "three", - Two = "two", -} -// github.com/foomo/gotsrpc/v2/example/multi/service.UnionStructAValueB -export enum UnionStructAValueB { - One = "one", - Three = "three", - Two = "two", -} -// github.com/foomo/gotsrpc/v2/example/multi/service.UnionStructB -export interface UnionStructB { - kind:'UnionStructB'; - value:github_com_foomo_gotsrpc_v2_example_multi_service.UnionStructAValueB; - foo:string; -} -// end of common js \ No newline at end of file diff --git a/example/nullable/main.go b/example/nullable/main.go index bba48f4..5fc3c4d 100644 --- a/example/nullable/main.go +++ b/example/nullable/main.go @@ -28,5 +28,5 @@ func main() { _ = exec.Command("open", "http://127.0.0.1:3000").Run() }() - _ = http.ListenAndServe("localhost:3000", mux) + panic(http.ListenAndServe("localhost:3000", mux)) } diff --git a/example/multi/client/index.html b/example/union/client/index.html similarity index 100% rename from example/multi/client/index.html rename to example/union/client/index.html diff --git a/example/multi/client/src/app.ts b/example/union/client/src/app.ts similarity index 100% rename from example/multi/client/src/app.ts rename to example/union/client/src/app.ts diff --git a/example/multi/client/src/service-client.ts b/example/union/client/src/service-client.ts similarity index 67% rename from example/multi/client/src/service-client.ts rename to example/union/client/src/service-client.ts index f472e24..909ba49 100644 --- a/example/multi/client/src/service-client.ts +++ b/example/union/client/src/service-client.ts @@ -1,22 +1,22 @@ /* eslint:disable */ // hello commonjs - we need some imports - sorted in alphabetical order, by go package -import * as github_com_foomo_gotsrpc_v2_example_multi_service from './service-vo'; // ./client/src/service-client.ts to ./client/src/service-vo.ts +import * as github_com_foomo_gotsrpc_v2_example_union_service from './service-vo'; // ./client/src/service-client.ts to ./client/src/service-vo.ts export class ServiceClient { public static defaultEndpoint = "/service"; constructor( public transport:(method: string, data?: any[]) => Promise ) {} - async inlineStruct():Promise { - return (await this.transport<{0:github_com_foomo_gotsrpc_v2_example_multi_service.InlineStruct}>("InlineStruct", []))[0] + async inlineStruct():Promise { + return (await this.transport<{0:github_com_foomo_gotsrpc_v2_example_union_service.InlineStruct}>("InlineStruct", []))[0] } - async inlineStructPtr():Promise { - return (await this.transport<{0:github_com_foomo_gotsrpc_v2_example_multi_service.InlineStructPtr}>("InlineStructPtr", []))[0] + async inlineStructPtr():Promise { + return (await this.transport<{0:github_com_foomo_gotsrpc_v2_example_union_service.InlineStructPtr}>("InlineStructPtr", []))[0] } - async unionString():Promise { - return (await this.transport<{0:github_com_foomo_gotsrpc_v2_example_multi_service.UnionString}>("UnionString", []))[0] + async unionString():Promise { + return (await this.transport<{0:github_com_foomo_gotsrpc_v2_example_union_service.UnionString}>("UnionString", []))[0] } - async unionStruct():Promise { - return (await this.transport<{0:github_com_foomo_gotsrpc_v2_example_multi_service.UnionStruct}>("UnionStruct", []))[0] + async unionStruct():Promise { + return (await this.transport<{0:github_com_foomo_gotsrpc_v2_example_union_service.UnionStruct}>("UnionStruct", []))[0] } } \ No newline at end of file diff --git a/example/union/client/src/service-vo.ts b/example/union/client/src/service-vo.ts new file mode 100644 index 0000000..5a0ba07 --- /dev/null +++ b/example/union/client/src/service-vo.ts @@ -0,0 +1,59 @@ +/* eslint:disable */ +// hello commonjs - we need some imports - sorted in alphabetical order, by go package +import * as github_com_foomo_gotsrpc_v2_example_union_service from './service-vo'; // ./client/src/service-vo.ts to ./client/src/service-vo.ts +// github.com/foomo/gotsrpc/v2/example/union/service.InlineStruct +export interface InlineStruct extends github_com_foomo_gotsrpc_v2_example_union_service.InlineStructA , github_com_foomo_gotsrpc_v2_example_union_service.InlineStructB { + value:string; +} +// github.com/foomo/gotsrpc/v2/example/union/service.InlineStructA +export interface InlineStructA { + valueA:string; +} +// github.com/foomo/gotsrpc/v2/example/union/service.InlineStructB +export interface InlineStructB { + valueB:string; +} +// github.com/foomo/gotsrpc/v2/example/union/service.InlineStructPtr +export interface InlineStructPtr extends Partial , Partial { + bug?:github_com_foomo_gotsrpc_v2_example_union_service.InlineStructB; + value:string; +} +// github.com/foomo/gotsrpc/v2/example/union/service.UnionString +export type UnionString = (typeof github_com_foomo_gotsrpc_v2_example_union_service.UnionStringA) & (typeof github_com_foomo_gotsrpc_v2_example_union_service.UnionStringB) +// github.com/foomo/gotsrpc/v2/example/union/service.UnionStringA +export enum UnionStringA { + One = "one", + Two = "two", +} +// github.com/foomo/gotsrpc/v2/example/union/service.UnionStringB +export enum UnionStringB { + Four = "four", + Three = "three", +} +// github.com/foomo/gotsrpc/v2/example/union/service.UnionStruct +export type UnionStruct = github_com_foomo_gotsrpc_v2_example_union_service.UnionStructA | github_com_foomo_gotsrpc_v2_example_union_service.UnionStructB | undefined +// github.com/foomo/gotsrpc/v2/example/union/service.UnionStructA +export interface UnionStructA { + kind:'UnionStructA'; + value:github_com_foomo_gotsrpc_v2_example_union_service.UnionStructAValueA; + bar:string; +} +// github.com/foomo/gotsrpc/v2/example/union/service.UnionStructAValueA +export enum UnionStructAValueA { + One = "one", + Three = "three", + Two = "two", +} +// github.com/foomo/gotsrpc/v2/example/union/service.UnionStructAValueB +export enum UnionStructAValueB { + One = "one", + Three = "three", + Two = "two", +} +// github.com/foomo/gotsrpc/v2/example/union/service.UnionStructB +export interface UnionStructB { + kind:'UnionStructB'; + value:github_com_foomo_gotsrpc_v2_example_union_service.UnionStructAValueB; + foo:string; +} +// end of common js \ No newline at end of file diff --git a/example/multi/client/src/transport.ts b/example/union/client/src/transport.ts similarity index 100% rename from example/multi/client/src/transport.ts rename to example/union/client/src/transport.ts diff --git a/example/multi/client/tsconfig.json b/example/union/client/tsconfig.json similarity index 100% rename from example/multi/client/tsconfig.json rename to example/union/client/tsconfig.json diff --git a/example/multi/go.mod b/example/union/go.mod similarity index 77% rename from example/multi/go.mod rename to example/union/go.mod index 7e1cc3d..74d5c45 100644 --- a/example/multi/go.mod +++ b/example/union/go.mod @@ -1,4 +1,4 @@ -module github.com/foomo/gotsrpc/v2/example/multi +module github.com/foomo/gotsrpc/v2/example/union go 1.16 diff --git a/example/multi/go.sum b/example/union/go.sum similarity index 100% rename from example/multi/go.sum rename to example/union/go.sum diff --git a/example/multi/gotsrpc.yml b/example/union/gotsrpc.yml similarity index 50% rename from example/multi/gotsrpc.yml rename to example/union/gotsrpc.yml index 3b80d8d..0c69713 100644 --- a/example/multi/gotsrpc.yml +++ b/example/union/gotsrpc.yml @@ -1,16 +1,16 @@ module: - name: github.com/foomo/gotsrpc/v2/example/multi + name: github.com/foomo/gotsrpc/v2/example/union path: ./ targets: - multi: + union: services: /service: Service - package: github.com/foomo/gotsrpc/v2/example/multi/service + package: github.com/foomo/gotsrpc/v2/example/union/service out: ./client/src/service-client.ts tsrpc: - Service mappings: - github.com/foomo/gotsrpc/v2/example/multi/service: + github.com/foomo/gotsrpc/v2/example/union/service: out: ./client/src/service-vo.ts diff --git a/example/multi/main.go b/example/union/main.go similarity index 80% rename from example/multi/main.go rename to example/union/main.go index f0bcac9..14d71a6 100644 --- a/example/multi/main.go +++ b/example/union/main.go @@ -9,7 +9,7 @@ import ( "github.com/davecgh/go-spew/spew" - "github.com/foomo/gotsrpc/v2/example/multi/service" + "github.com/foomo/gotsrpc/v2/example/union/service" ) func main() { @@ -26,15 +26,16 @@ func main() { } }) - go exec.Command("open", "http://127.0.0.1:3000").Run() - go call() + go func() { + time.Sleep(time.Second) + _ = exec.Command("open", "http://127.0.0.1:3000").Run() + call() + }() - http.ListenAndServe("localhost:3000", mux) + panic(http.ListenAndServe("localhost:3000", mux)) } func call() { - time.Sleep(time.Second) - c := service.NewDefaultServiceGoTSRPCClient("http://127.0.0.1:3000") { diff --git a/example/multi/service/gotsrpc_gen.go b/example/union/service/gotsrpc_gen.go similarity index 97% rename from example/multi/service/gotsrpc_gen.go rename to example/union/service/gotsrpc_gen.go index 811c4e4..60bc496 100644 --- a/example/multi/service/gotsrpc_gen.go +++ b/example/union/service/gotsrpc_gen.go @@ -12,8 +12,8 @@ import ( ) func init() { - gotsrpc.MustRegisterUnionExt(UnionStruct{}) gotsrpc.MustRegisterUnionExt(UnionString{}) + gotsrpc.MustRegisterUnionExt(UnionStruct{}) } const ( @@ -54,7 +54,7 @@ func (p *ServiceGoTSRPCProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) callStats := gotsrpc.GetStatsForRequest(r) if callStats != nil { callStats.Func = funcName - callStats.Package = "github.com/foomo/gotsrpc/v2/example/multi/service" + callStats.Package = "github.com/foomo/gotsrpc/v2/example/union/service" callStats.Service = "Service" } switch funcName { diff --git a/example/multi/service/gotsrpcclient_gen.go b/example/union/service/gotsrpcclient_gen.go similarity index 100% rename from example/multi/service/gotsrpcclient_gen.go rename to example/union/service/gotsrpcclient_gen.go diff --git a/example/multi/service/handler.go b/example/union/service/handler.go similarity index 87% rename from example/multi/service/handler.go rename to example/union/service/handler.go index e76627a..4e67d1c 100644 --- a/example/multi/service/handler.go +++ b/example/union/service/handler.go @@ -20,6 +20,6 @@ func (h *Handler) UnionString(w http.ResponseWriter, r *http.Request) (e UnionSt } func (h *Handler) UnionStruct(w http.ResponseWriter, r *http.Request) (e UnionStruct) { - //return UnionStruct{UnionStructA: UnionStructA{Kind: "UnionStructA", Value: UnionStructAValueAOne}} + // return UnionStruct{UnionStructA: UnionStructA{Kind: "UnionStructA", Value: UnionStructAValueAOne}} return UnionStruct{B: &UnionStructB{Kind: "UnionStructB", Value: UnionStructAValueBOne}} } diff --git a/example/multi/service/service.go b/example/union/service/service.go similarity index 100% rename from example/multi/service/service.go rename to example/union/service/service.go diff --git a/example/multi/service/vo.go b/example/union/service/vo.go similarity index 99% rename from example/multi/service/vo.go rename to example/union/service/vo.go index 0763df9..7942396 100644 --- a/example/multi/service/vo.go +++ b/example/union/service/vo.go @@ -31,7 +31,9 @@ type ( type ( UnionString struct { A *UnionStringA `json:"a,omitempty,union"` + B *UnionStringB `json:"b,omitempty,union"` + c string } UnionStringA string UnionStringB string