From 27970f389b09d63de090eb01ac0697be73af57ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sedl=C3=A1=C4=8Dek?= Date: Wed, 6 Nov 2024 12:03:12 +0100 Subject: [PATCH] WebrpcMethods(), var methods indentation (#77) * methods function * examples * Methods() -> WebrpcMethods() --- _examples/golang-basics/example.gen.go | 73 ++++++++++++++------------ _examples/golang-imports/api.gen.go | 43 ++++++++------- types.go.tmpl | 35 ++++++------ 3 files changed, 84 insertions(+), 67 deletions(-) diff --git a/_examples/golang-basics/example.gen.go b/_examples/golang-basics/example.gen.go index 0214c0b..a2f25c2 100644 --- a/_examples/golang-basics/example.gen.go +++ b/_examples/golang-basics/example.gen.go @@ -224,40 +224,47 @@ type GenVersions struct { SchemaVersion string `json:"SchemaVersion"` } -var ( - methods = map[string]method{ - "/rpc/ExampleService/Ping": { - Name: "Ping", - Service: "ExampleService", - Annotations: map[string]string{}, - }, - "/rpc/ExampleService/Status": { - Name: "Status", - Service: "ExampleService", - Annotations: map[string]string{"internal": ""}, - }, - "/rpc/ExampleService/Version": { - Name: "Version", - Service: "ExampleService", - Annotations: map[string]string{}, - }, - "/rpc/ExampleService/GetUser": { - Name: "GetUser", - Service: "ExampleService", - Annotations: map[string]string{"deprecated": ""}, - }, - "/rpc/ExampleService/FindUser": { - Name: "FindUser", - Service: "ExampleService", - Annotations: map[string]string{}, - }, - "/rpc/ExampleService/LogEvent": { - Name: "LogEvent", - Service: "ExampleService", - Annotations: map[string]string{}, - }, +var methods = map[string]method{ + "/rpc/ExampleService/Ping": { + Name: "Ping", + Service: "ExampleService", + Annotations: map[string]string{}, + }, + "/rpc/ExampleService/Status": { + Name: "Status", + Service: "ExampleService", + Annotations: map[string]string{"internal": ""}, + }, + "/rpc/ExampleService/Version": { + Name: "Version", + Service: "ExampleService", + Annotations: map[string]string{}, + }, + "/rpc/ExampleService/GetUser": { + Name: "GetUser", + Service: "ExampleService", + Annotations: map[string]string{"deprecated": ""}, + }, + "/rpc/ExampleService/FindUser": { + Name: "FindUser", + Service: "ExampleService", + Annotations: map[string]string{}, + }, + "/rpc/ExampleService/LogEvent": { + Name: "LogEvent", + Service: "ExampleService", + Annotations: map[string]string{}, + }, +} + +func WebrpcMethods() map[string]method { + res := make(map[string]method, len(methods)) + for k, v := range methods { + res[k] = v } -) + + return res +} var WebRPCServices = map[string][]string{ "ExampleService": { diff --git a/_examples/golang-imports/api.gen.go b/_examples/golang-imports/api.gen.go index e6b7bb9..3a7158f 100644 --- a/_examples/golang-imports/api.gen.go +++ b/_examples/golang-imports/api.gen.go @@ -139,25 +139,32 @@ func (x *Location) Is(values ...Location) bool { return false } -var ( - methods = map[string]method{ - "/rpc/ExampleAPI/Ping": { - Name: "Ping", - Service: "ExampleAPI", - Annotations: map[string]string{}, - }, - "/rpc/ExampleAPI/Status": { - Name: "Status", - Service: "ExampleAPI", - Annotations: map[string]string{}, - }, - "/rpc/ExampleAPI/GetUsers": { - Name: "GetUsers", - Service: "ExampleAPI", - Annotations: map[string]string{}, - }, +var methods = map[string]method{ + "/rpc/ExampleAPI/Ping": { + Name: "Ping", + Service: "ExampleAPI", + Annotations: map[string]string{}, + }, + "/rpc/ExampleAPI/Status": { + Name: "Status", + Service: "ExampleAPI", + Annotations: map[string]string{}, + }, + "/rpc/ExampleAPI/GetUsers": { + Name: "GetUsers", + Service: "ExampleAPI", + Annotations: map[string]string{}, + }, +} + +func WebrpcMethods() map[string]method { + res := make(map[string]method, len(methods)) + for k, v := range methods { + res[k] = v } -) + + return res +} var WebRPCServices = map[string][]string{ "ExampleAPI": { diff --git a/types.go.tmpl b/types.go.tmpl index ae96771..9776cc8 100644 --- a/types.go.tmpl +++ b/types.go.tmpl @@ -29,23 +29,26 @@ {{- end }} -var ( - methods = map[string]method{ - {{- range $_, $service := $services -}} - {{- range $_, $method := $service.Methods }} - "/rpc/{{$service.Name}}/{{$method.Name}}": { - Name: "{{$method.Name}}", - Service: "{{$service.Name}}", - Annotations: map[string]string{ - {{- range $_, $annotation := $method.Annotations -}} - "{{$annotation.AnnotationType}}": "{{$annotation.Value}}", - {{- end -}} - }, - }, - {{- end -}} - {{ end }} +var methods = map[string]method{ + {{- range $_, $service := $services -}} + {{- range $_, $method := $service.Methods }} + "/rpc/{{$service.Name}}/{{$method.Name}}": { + Name: "{{$method.Name}}", + Service: "{{$service.Name}}", + Annotations: map[string]string{ {{- range $_, $annotation := $method.Annotations -}}"{{$annotation.AnnotationType}}": "{{$annotation.Value}}", {{- end -}} }, + }, + {{- end -}} + {{ end }} +} + +func WebrpcMethods() map[string]method { + res := make(map[string]method, len(methods)) + for k, v := range methods { + res[k] = v } -) + + return res +} var WebRPCServices = map[string][]string{ {{- range $_, $service := $services}}