Skip to content

Commit b7a68b2

Browse files
authored
Fix server imports & indentation (#25)
1 parent ecf16d3 commit b7a68b2

File tree

4 files changed

+19
-18
lines changed

4 files changed

+19
-18
lines changed

client.go.tmpl

+2-2
Original file line numberDiff line numberDiff line change
@@ -188,5 +188,5 @@ func HTTPRequestHeaders(ctx context.Context) (http.Header, bool) {
188188
return h, ok
189189
}
190190

191-
{{- end}}
192-
{{- end }}
191+
{{- end -}}
192+
{{- end -}}

imports.go.tmpl

+10-11
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import (
4444
{{- end -}}
4545

4646
{{- /* Print custom type imports. */ -}}
47-
{{ $imports := dict }}
47+
{{- $imports := dict -}}
4848

4949
{{- if eq $opts.json "stdlib" -}}
5050
{{- /* Already imported in the stdlib section. */ -}}
@@ -55,28 +55,27 @@ import (
5555
{{- exit 1 -}}
5656
{{- end -}}
5757

58-
{{ if ne $opts.importTypesFrom "" }}
59-
60-
"{{ $opts.importTypesFrom }}"
61-
{{- else }}
62-
{{ range $_, $type := $types -}}
58+
{{- if ne $opts.importTypesFrom "" }}
59+
{{- set $imports $opts.importTypesFrom "" -}}
60+
{{- else -}}
61+
{{- range $_, $type := $types -}}
6362
{{- range $_, $field := $type.Fields -}}
6463
{{- range $meta := $field.Meta -}}
6564
{{- if exists $meta "go.type.import" -}}
6665
{{- set $imports (get $meta "go.type.import") "" -}}
6766
{{- end -}}
6867
{{- end -}}
6968
{{- end -}}
70-
{{- end }}
71-
{{- range $import, $rename := $imports }}
72-
{{if ne $rename ""}}{{$rename}} {{end}}"{{$import}}"
7369
{{- end -}}
74-
{{ end }}
70+
{{- end }}
71+
{{ range $import, $rename := $imports }}
72+
{{if ne $rename ""}}{{$rename}} {{end}}"{{$import}}"
73+
{{- end }}
7574
)
7675

7776
{{- if eq $opts.json "jsoniter" }}
7877

7978
var json = jsoniter.ConfigCompatibleWithStandardLibrary
80-
{{ end -}}
79+
{{- end -}}
8180

8281
{{- end -}}

main.go.tmpl

+5-3
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,17 @@ func WebRPCSchemaHash() string {
8484
return "{{.SchemaHash}}"
8585
}
8686

87-
{{ if eq $opts.importTypesFrom "" -}}
87+
{{- printf "\n" -}}
88+
89+
{{- if eq $opts.importTypesFrom "" }}
8890
{{ template "types" dict "Services" .Services "Types" .Types "TypeMap" $typeMap "TypePrefix" $typePrefix}}
89-
{{- end }}
91+
{{ end -}}
9092

9193
{{- if $opts.server}}
9294
{{ template "server" dict "Services" .Services "TypeMap" $typeMap "TypePrefix" $typePrefix }}
9395
{{ end -}}
9496

95-
{{- if $opts.client }}
97+
{{ if $opts.client }}
9698
{{ template "client" dict "Services" .Services "TypeMap" $typeMap "TypePrefix" $typePrefix }}
9799
{{ end -}}
98100

server.go.tmpl

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
{{define "server"}}
1+
{{- define "server"}}
22
{{- $typeMap := .TypeMap -}}
33
{{- $typePrefix := .TypePrefix -}}
4-
{{- if .Services }}
4+
{{- if .Services -}}
55
//
66
// Server
77
//

0 commit comments

Comments
 (0)