Skip to content

Commit 3ef0300

Browse files
method getter functions (#91)
* method getter functions * fix unnecessary empty line, on methods with no input arguments
1 parent 1d80d62 commit 3ef0300

File tree

5 files changed

+95
-46
lines changed

5 files changed

+95
-46
lines changed

_examples/golang-basics/example.gen.go

Lines changed: 40 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

_examples/golang-imports/api.gen.go

Lines changed: 29 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client.go.tmpl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,16 @@ func (c *{{$serviceNameClient}}) {{$method.Name}}(ctx context.Context{{range $_,
4949
{{- range $i, $input := $method.Inputs}}
5050
Arg{{$i}} {{template "field" dict "Name" $input.Name "Type" $input.Type "Optional" $input.Optional "TypeMap" $typeMap "TypePrefix" $typePrefix "TypeMeta" $input.Meta "JsonTags" true}}
5151
{{- end}}
52-
}{ {{- range $i, $input := $method.Inputs}}{{if gt $i 0}}, {{end}}{{$input.Name}}{{end}}}
52+
}{ {{- range $i, $input := $method.Inputs}}{{if gt $i 0}}, {{end}}{{$input.Name}}{{end}}}{{ "\n" }}
5353
{{- end}}
5454
{{- if $method.Outputs | len}}
5555
{{- $outputVar = "&out"}}
5656
out := struct {
5757
{{- range $i, $output := $method.Outputs}}
5858
Ret{{$i}} {{template "field" dict "Name" $output.Name "Type" $output.Type "Optional" $output.Optional "TypeMap" $typeMap "TypePrefix" $typePrefix "TypeMeta" $output.Meta "JsonTags" true}}
5959
{{- end}}
60-
}{}
60+
}{}{{ "\n" }}
6161
{{- end }}
62-
6362
resp, err := doHTTPRequest(ctx, c.client, c.urls[{{$i}}], {{$inputVar}}, {{$outputVar}})
6463
if resp != nil {
6564
cerr := resp.Body.Close()
@@ -81,9 +80,8 @@ func (c *{{$serviceNameClient}}) {{$method.Name}}(ctx context.Context{{range $_,
8180
{{- range $i, $input := $method.Inputs}}
8281
Arg{{$i}} {{template "field" dict "Name" $input.Name "Type" $input.Type "Optional" $input.Optional "TypeMap" $typeMap "TypePrefix" $typePrefix "TypeMeta" $input.Meta "JsonTags" true}}
8382
{{- end}}
84-
}{ {{- range $i, $input := $method.Inputs}}{{if gt $i 0}}, {{end}}{{$input.Name}}{{end}}}
83+
}{ {{- range $i, $input := $method.Inputs}}{{if gt $i 0}}, {{end}}{{$input.Name}}{{end}}}{{ "\n" }}
8584
{{- end}}
86-
8785
resp, err := doHTTPRequest(ctx, c.client, c.urls[{{$i}}], {{$inputVar}}, nil)
8886
if err != nil {
8987
if resp != nil {

helpers.go.tmpl

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,26 @@
66
//
77

88
type method struct {
9-
Name string
10-
Service string
11-
Annotations map[string]string
9+
name string
10+
service string
11+
annotations map[string]string
12+
}
13+
14+
func (m method)Name() string {
15+
return m.name
16+
}
17+
18+
func (m method)Service() string {
19+
return m.service
20+
}
21+
22+
func (m method)Annotations() map[string]string {
23+
res := make(map[string]string, len(m.annotations))
24+
for k, v := range m.annotations {
25+
res[k] = v
26+
}
27+
28+
return res
1229
}
1330

1431
type contextKey struct {

types.go.tmpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ var methods = map[string]method{
3333
{{- range $_, $service := $services -}}
3434
{{- range $_, $method := $service.Methods }}
3535
"/rpc/{{$service.Name}}/{{$method.Name}}": {
36-
Name: "{{$method.Name}}",
37-
Service: "{{$service.Name}}",
38-
Annotations: map[string]string{ {{- range $_, $annotation := $method.Annotations -}}"{{$annotation.AnnotationType}}": "{{$annotation.Value}}", {{- end -}} },
36+
name: "{{$method.Name}}",
37+
service: "{{$service.Name}}",
38+
annotations: map[string]string{ {{- range $_, $annotation := $method.Annotations -}}"{{$annotation.AnnotationType}}": "{{$annotation.Value}}", {{- end -}} },
3939
},
4040
{{- end -}}
4141
{{ end }}

0 commit comments

Comments
 (0)