From b63daec87ba6d2b727f4e4b9376b4896e1ce0949 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sedl=C3=A1=C4=8Dek?= Date: Mon, 29 Apr 2024 13:43:38 +0200 Subject: [PATCH] updated examples --- _examples/golang-basics/example.gen.go | 13 ++++++++++++- _examples/golang-imports/api.gen.go | 10 +++++++++- _examples/golang-imports/main.go | 7 +++---- types.go.tmpl | 12 ++++++------ 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/_examples/golang-basics/example.gen.go b/_examples/golang-basics/example.gen.go index 632dd51..773a43c 100644 --- a/_examples/golang-basics/example.gen.go +++ b/_examples/golang-basics/example.gen.go @@ -1,6 +1,6 @@ // example v0.0.1 3a3a4087149f1118f0b9494fa254afab46564a1b // -- -// Code generated by webrpc-gen@v0.18.3 with ../../../gen-golang generator. DO NOT EDIT. +// Code generated by webrpc-gen@v0.18.1 with ../../../gen-golang generator. DO NOT EDIT. // // webrpc-gen -schema=example.ridl -target=../../../gen-golang -pkg=main -server -client -legacyErrors -fixEmptyArrays -out=./example.gen.go package main @@ -171,6 +171,17 @@ var WebRPCServices = map[string][]string{ }, } +type Route struct{} + +var WebRPCServicesMap = map[string]Route{ + "/rpc/ExampleService/Ping": {}, + "/rpc/ExampleService/Status": {}, + "/rpc/ExampleService/Version": {}, + "/rpc/ExampleService/GetUser": {}, + "/rpc/ExampleService/FindUser": {}, + "/rpc/ExampleService/LogEvent": {}, +} + // // Server types // diff --git a/_examples/golang-imports/api.gen.go b/_examples/golang-imports/api.gen.go index cd3a6a8..0976a9f 100644 --- a/_examples/golang-imports/api.gen.go +++ b/_examples/golang-imports/api.gen.go @@ -1,6 +1,6 @@ // example-api-service v1.0.0 eb9a5d4082a36a8cb84eaa4b3e1091fc4f1f6f3d // -- -// Code generated by webrpc-gen@v0.18.3 with ../../../gen-golang generator. DO NOT EDIT. +// Code generated by webrpc-gen@v0.18.1 with ../../../gen-golang generator. DO NOT EDIT. // // webrpc-gen -schema=./proto/api.ridl -target=../../../gen-golang -out=./api.gen.go -pkg=main -server -client -legacyErrors=true -fmt=false package main @@ -92,6 +92,14 @@ var WebRPCServices = map[string][]string{ }, } +type Route struct{} + +var WebRPCServicesMap = map[string]Route{ + "/rpc/ExampleAPI/Ping": {}, + "/rpc/ExampleAPI/Status": {}, + "/rpc/ExampleAPI/GetUsers": {}, +} + // // Server types // diff --git a/_examples/golang-imports/main.go b/_examples/golang-imports/main.go index 5a12100..44fec3c 100644 --- a/_examples/golang-imports/main.go +++ b/_examples/golang-imports/main.go @@ -33,8 +33,7 @@ func startServer() error { return http.ListenAndServe(":4242", r) } -type ExampleRPC struct { -} +type ExampleRPC struct{} func (s *ExampleRPC) Ping(ctx context.Context) error { return nil @@ -44,9 +43,9 @@ func (s *ExampleRPC) Status(ctx context.Context) (bool, error) { return true, nil } -func (s *ExampleRPC) GetUsers(ctx context.Context) ([]*User, *Location, error) { +func (s *ExampleRPC) GetUsers(ctx context.Context) ([]*User, Location, error) { loc := Location_TORONTO return []*User{ {Username: "pk", Age: 99}, - }, &loc, nil + }, loc, nil } diff --git a/types.go.tmpl b/types.go.tmpl index ab75468..ab6a19d 100644 --- a/types.go.tmpl +++ b/types.go.tmpl @@ -39,13 +39,13 @@ var WebRPCServices = map[string][]string{ {{- end}} } -var WebRPCServicesMap = map[string]map[string]struct{}{ +type Route struct{} + +var WebRPCServicesMap = map[string]Route{ {{- range $_, $service := $services}} - "{{$service.Name}}": { - {{- range $_, $method := $service.Methods}} - "{{$method.Name}}": struct{}{}, - {{- end}} - }, + {{- range $_, $method := $service.Methods}} + "/rpc/{{$service.Name}}/{{$method.Name}}": {}, + {{- end}} {{- end}} }