Skip to content

Commit 7444b7a

Browse files
Always end template files in a newline (#3687)
* End all grpc templates in newlines - Remove spurious newline in parse_endpoint - Update test (leave trailing whitespace alone) * End all http templates in newlines - request_init.go.tpl needs to strip it - Most partials need to strip, but handle once inside templates.go * End all services and example templates in newlines - codegen/service/templates/return_type_init.go.tpl removes this with a trailing dash, as the say it's consumed through validations is hard to follow and fix - example now spaces out before var(){} blocks including after flag.Parse() --------- Co-authored-by: Raphael Simon <[email protected]>
1 parent 18d5007 commit 7444b7a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+58
-48
lines changed

codegen/example/templates/client_end.go.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
m, _ := json.MarshalIndent(data, "", " ")
1111
fmt.Println(string(m))
1212
}
13-
}
13+
}

codegen/example/templates/client_endpoint_init.go.tpl

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
var(
2+
var(
33
endpoint goa.Endpoint
44
payload any
55
err error
@@ -22,4 +22,4 @@ var(
2222
fmt.Fprintln(os.Stderr, err.Error())
2323
fmt.Fprintln(os.Stderr, "run '"+os.Args[0]+" --help' for detailed usage.")
2424
os.Exit(1)
25-
}
25+
}

codegen/example/templates/client_start.go.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ func main() {
1111
timeoutF = flag.Int("timeout", 30, "Maximum number of seconds to wait for response")
1212
)
1313
flag.Usage = usage
14-
flag.Parse()
14+
flag.Parse()

codegen/example/templates/client_var_init.go.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@ var (
5151
}
5252
scheme = u.Scheme
5353
host = u.Host
54-
}
54+
}

codegen/example/templates/server_end.go.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88

99
wg.Wait()
1010
log.Printf(ctx, "exited")
11-
}
11+
}

codegen/example/templates/server_endpoints.go.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
{{- end }}
1818
{{- end }}
1919
}
20-
{{- end }}
20+
{{- end }}

codegen/example/templates/server_handler.go.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@
5151
{{- end }}
5252
default:
5353
log.Fatal(ctx, fmt.Errorf("invalid host argument: %q (valid hosts: {{ join .Server.AvailableHosts "|" }})", *hostF))
54-
}
54+
}

codegen/example/templates/server_interceptors.go.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
{{- end }}
1717
}
1818
{{- end }}
19-
{{- end }}
19+
{{- end }}

codegen/example/templates/server_interrupts.go.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
}()
1414

1515
var wg sync.WaitGroup
16-
ctx, cancel := context.WithCancel(ctx)
16+
ctx, cancel := context.WithCancel(ctx)

codegen/example/templates/server_logger.go.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
ctx = log.Context(ctx, log.WithDebug())
1111
log.Debugf(ctx, "debug logs enabled")
1212
}
13-
log.Print(ctx, log.KV{K: "http-port", V: *httpPortF})
13+
log.Print(ctx, log.KV{K: "http-port", V: *httpPortF})

codegen/example/templates/server_services.go.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
{{- end }}
1616
{{- end }}
1717
}
18-
{{- end }}
18+
{{- end }}

codegen/example/templates/server_start.go.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ func main() {
1313
secureF = flag.Bool("secure", false, "Use secure scheme (https or grpcs)")
1414
dbgF = flag.Bool("debug", false, "Log request and response bodies")
1515
)
16-
flag.Parse()
16+
flag.Parse()

codegen/example/testdata/client-no-server.golden

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ func main() {
99
)
1010
flag.Usage = usage
1111
flag.Parse()
12+
1213
var (
1314
addr string
1415
timeout int
@@ -42,6 +43,7 @@ func main() {
4243
scheme = u.Scheme
4344
host = u.Host
4445
}
46+
4547
var (
4648
endpoint goa.Endpoint
4749
payload any

codegen/example/testdata/client-single-server-multiple-hosts-with-variables.golden

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ func main() {
1212
)
1313
flag.Usage = usage
1414
flag.Parse()
15+
1516
var (
1617
addr string
1718
timeout int
@@ -63,6 +64,7 @@ func main() {
6364
scheme = u.Scheme
6465
host = u.Host
6566
}
67+
6668
var (
6769
endpoint goa.Endpoint
6870
payload any

codegen/example/testdata/client-single-server-multiple-hosts.golden

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ func main() {
99
)
1010
flag.Usage = usage
1111
flag.Parse()
12+
1213
var (
1314
addr string
1415
timeout int
@@ -44,6 +45,7 @@ func main() {
4445
scheme = u.Scheme
4546
host = u.Host
4647
}
48+
4749
var (
4850
endpoint goa.Endpoint
4951
payload any

codegen/example/testdata/client-single-server-single-host-with-variables.golden

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ func main() {
1818
)
1919
flag.Usage = usage
2020
flag.Parse()
21+
2122
var (
2223
addr string
2324
timeout int
@@ -60,6 +61,7 @@ func main() {
6061
scheme = u.Scheme
6162
host = u.Host
6263
}
64+
6365
var (
6466
endpoint goa.Endpoint
6567
payload any

codegen/example/testdata/client-single-server-single-host.golden

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ func main() {
99
)
1010
flag.Usage = usage
1111
flag.Parse()
12+
1213
var (
1314
addr string
1415
timeout int
@@ -42,6 +43,7 @@ func main() {
4243
scheme = u.Scheme
4344
host = u.Host
4445
}
46+
4547
var (
4648
endpoint goa.Endpoint
4749
payload any

codegen/service/templates/return_type_init.go.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@
3737
}
3838
{{- end }}
3939
return {{ .ReturnVar }}
40-
{{- end }}
40+
{{- end -}}

codegen/service/templates/service_endpoint_stream_struct.go.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ type {{ .ServerStream.EndpointStruct }} struct {
88
{{- end }}
99
{{ printf "Stream is the server stream used by the %q method to send data." .Name | comment }}
1010
Stream {{ .ServerStream.Interface }}
11-
}
11+
}

codegen/service/templates/service_endpoints_init.go.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ func New{{ .VarName }}(s {{ .ServiceVarName }}{{ if .HasServerInterceptors }}, s
2222
{{- end }}
2323
return endpoints
2424
{{- end }}
25-
}
25+
}

codegen/service/templates/service_endpoints_use.go.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ func (e *{{ .VarName }}) Use(m func(goa.Endpoint) goa.Endpoint) {
55
{{- range .Methods }}
66
e.{{ .VarName }} = m(e.{{ .VarName }})
77
{{- end }}
8-
}
8+
}

grpc/codegen/templates/client_init.go.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ func New{{ .ClientStruct }}(cc *grpc.ClientConn, opts ...grpc.CallOption) *{{ .C
44
grpccli: {{ .ClientInterfaceInit }}(cc),
55
opts: opts,
66
}
7-
}
7+
}

grpc/codegen/templates/client_struct.go.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
type {{ .ClientStruct }} struct {
33
grpccli {{ .PkgName }}.{{ .ClientInterface }}
44
opts []grpc.CallOption
5-
}
5+
}

grpc/codegen/templates/do_grpc_cli.go.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ func grpcUsageCommands() string {
2626
func grpcUsageExamples() string {
2727
return cli.UsageExamples()
2828
}
29-
{{- end }}
29+
{{- end }}

grpc/codegen/templates/parse_endpoint.go.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func ParseEndpoint(
2222
c := {{ .PkgName }}.NewClient(cc, opts...)
2323
switch epn {
2424
{{- $pkgName := .PkgName }}
25-
{{ range .Subcommands }}
25+
{{- range .Subcommands }}
2626
case "{{ .Name }}":
2727
endpoint = c.{{ .MethodVarName }}()
2828
{{- if .Interceptors }}

grpc/codegen/templates/partial/convert_string_to_type.go.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,4 @@
156156
{{- else }}
157157
// unsupported type {{ .Type.Name }} for var {{ .VarName }}
158158
{{- end }}
159-
{{- end }}
159+
{{- end }}

grpc/codegen/templates/partial/convert_type_to_string.go.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@
2626
{{- else }}
2727
// unsupported type {{ .Type.Name }} for field {{ .FieldName }}
2828
{{- end }}
29-
{{- end }}
29+
{{- end }}

grpc/codegen/templates/remote_method_builder.go.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ func Build{{ .Method.VarName }}Func(grpccli {{ .PkgName }}.{{ .ClientInterface }
99
}
1010
return grpccli.{{ .ClientMethodName }}(ctx{{ if not .Method.StreamingPayload }}, &{{ .Request.ClientConvert.TgtName }}{}{{ end }}, opts...)
1111
}
12-
}
12+
}

grpc/codegen/templates/request_encoder.go.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ func Encode{{ .Method.VarName }}Request(ctx context.Context, v any, md *metadata
4343
{{- else }}
4444
return nil, nil
4545
{{- end }}
46-
}
46+
}

grpc/codegen/templates/response_decoder.go.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,4 @@ func Decode{{ .Method.VarName }}Response(ctx context.Context, v any, hdr, trlr m
116116
}
117117
{{- end }}
118118
{{- end }}
119-
{{- end }}
119+
{{- end }}

grpc/codegen/testdata/endpoint-endpoint-with-interceptors.golden

-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ func ParseEndpoint(
117117
case "service-with-interceptors":
118118
c := servicewithinterceptorsc.NewClient(cc, opts...)
119119
switch epn {
120-
121120
case "method-a":
122121
endpoint = c.MethodA()
123122
endpoint = servicewithinterceptors.WrapMethodAClientEndpoint(endpoint, inter)

http/codegen/templates.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func readTemplate(name string, partials ...string) string {
2121
panic("failed to read partial template " + partial + ": " + err.Error()) // Should never happen, bug if it does
2222
}
2323
partialDefs = append(partialDefs,
24-
fmt.Sprintf("{{ define \"partial_%s\" }}\n%s{{ end }}", partial, string(tmpl)))
24+
fmt.Sprintf("{{- define \"partial_%s\" }}\n%s{{- end }}", partial, string(tmpl)))
2525
}
2626
prefix = strings.Join(partialDefs, "\n")
2727
}

http/codegen/templates/append_fs.go.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ func (s appendFS) Open(name string) (http.File, error) {
2121
// before delegating to the provided embed.FS.
2222
func appendPrefix(fsys http.FileSystem, prefix string) http.FileSystem {
2323
return appendFS{prefix: prefix, fs: fsys}
24-
}
24+
}

http/codegen/templates/cli_end.go.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ return cli.ParseEndpoint(
2626
{{- end }}
2727
{{- end }}
2828
)
29-
}
29+
}

http/codegen/templates/partial/client_map_conversion.go.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ for k{{ if not (eq .Type.KeyType.Type.Name "string") }}Raw{{ end }}, value := ra
2020
{{ template "partial_client_type_conversion" (typeConversionData .Type.ElemType.Type .FieldType.ElemType.Type "valueStr" "value") }}
2121
values.Add(key, valueStr)
2222
{{- end }}
23-
}
23+
}

http/codegen/templates/partial/client_type_conversion.go.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@
2424
{{ .VarName }} := fmt.Sprintf("%v", {{ .Target }})
2525
{{- else }}
2626
// unsupported type {{ .Type.Name }} for field {{ .FieldName }}
27-
{{- end }}
27+
{{- end }}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{{ .VarName }} = make({{ goTypeRef .Type }}, len({{ .VarName }}Raw))
22
for i, rv := range {{ .VarName }}Raw {
33
{{- template "partial_slice_item_conversion" . }}
4-
}
4+
}

http/codegen/templates/partial/header_conversion.go.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@
3535
{{- end }}
3636
{{- else }}
3737
// unsupported type {{ .Type.Name }} for header field {{ .FieldName }}
38-
{{- end }}
38+
{{- end }}

http/codegen/templates/partial/path_conversion.go.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
}
77
{{- else }}
88
{{- template "partial_query_type_conversion" . }}
9-
{{- end }}
9+
{{- end }}

http/codegen/templates/partial/query_map_conversion.go.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@
4040
{{- template "partial_query_type_conversion" (conversionData (printf "val%s" .Loop) "query" .Type.ElemType.Type) }}
4141
}
4242
{{ .VarName }}[key{{ .Loop }}] = val{{ .Loop }}
43-
{{- end }}
43+
{{- end }}

http/codegen/templates/partial/query_slice_conversion.go.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
{{- else if eq . "boolean" }} strconv.FormatBool(v)
99
{{- else if eq . "bytes" }} url.QueryEscape(string(v))
1010
{{- else }} url.QueryEscape(fmt.Sprintf("%v", v))
11-
{{- end }}
11+
{{- end }}

http/codegen/templates/partial/query_type_conversion.go.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,4 @@
8181
{{ if and (ne .TypeRef nil) (and (ne .TypeRef "bool") (ne .TypeRef "*bool")) }}{{ .VarName }} = ({{.TypeRef}})({{ if .Pointer }}&{{ end }}v){{ else }}{{ .VarName }} = {{ if .Pointer }}&{{ end }}v{{ end }}
8282
{{- else }}
8383
// unsupported type {{ .Type.Name }} for var {{ .VarName }}
84-
{{- end }}
84+
{{- end }}

http/codegen/templates/partial/request_elements.go.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -345,4 +345,4 @@ qp := r.URL.Query()
345345
{{ .Validate }}
346346
{{- end }}
347347
{{- end }}
348-
{{- end -}}
348+
{{- end }}

http/codegen/templates/partial/response.go.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,4 @@
116116
{{- if .ErrorHeader }}
117117
w.Header().Set("goa-error", res.GoaErrorName())
118118
{{- end }}
119-
w.WriteHeader({{ .StatusCode }})
119+
w.WriteHeader({{ .StatusCode }})

http/codegen/templates/partial/single_response.go.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,4 @@
184184
return nil, goahttp.ErrValidationError("{{ $.ServiceName }}", "{{ $.Method.Name }}", err)
185185
}
186186
{{- end }}
187-
{{- end }}
187+
{{- end }}

http/codegen/templates/partial/slice_item_conversion.go.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,4 @@
6060
{{ .VarName }}[i] = rv
6161
{{- else }}
6262
// unsupported slice type {{ .Type.ElemType.Type.Name }} for var {{ .VarName }}
63-
{{- end }}
63+
{{- end }}

http/codegen/templates/partial/websocket_upgrade.go.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@
3030
})
3131
if err != nil {
3232
return {{ if eq .Function "Recv" }}rv, {{ end }}err
33-
}
33+
}

http/codegen/templates/path.go.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
func {{ .PathInit.Name }}({{ range .PathInit.ServerArgs }}{{ .VarName }} {{ .TypeRef }}, {{ end }}) {{ .PathInit.ReturnTypeRef }} {
33
{{- .PathInit.ServerCode }}
44
}
5-
{{ end }}
5+
{{ end }}

http/codegen/templates/path_init.go.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
{{- end }}, {{ end }})
1616
{{- else }}
1717
return "{{ .PathFormat }}"
18-
{{- end }}
18+
{{- end -}}

0 commit comments

Comments
 (0)