Skip to content

Commit

Permalink
generate only if includeHeaders option is set
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasJenicek committed Oct 16, 2024
1 parent 603d10a commit 6dadae4
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 14 deletions.
12 changes: 6 additions & 6 deletions _examples/golang-basics/example.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion _examples/golang-basics/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:generate webrpc-gen -schema=example.ridl -target=../../../gen-golang -pkg=main -server -client -legacyErrors -fixEmptyArrays -out=./example.gen.go
//go:generate webrpc-gen -schema=example.ridl -target=../../../gen-golang -pkg=main -server -client -legacyErrors -fixEmptyArrays -includeHeaders -out=./example.gen.go
package main

import (
Expand Down
9 changes: 4 additions & 5 deletions _examples/golang-imports/api.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion client.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ func newRequest(ctx context.Context, url string, reqBody io.Reader, contentType
}
req.Header.Set("Accept", contentType)
req.Header.Set("Content-Type", contentType)
req.Header.Set(WebRpcHeaderName, WebRpcHeader)
{{- if $opts.includeHeaders }}
req.Header.Set(WebRpcHeader, WebRpcHeaderValue)
{{- end }}
if headers, ok := HTTPRequestHeaders(ctx); ok {
for k := range headers {
for _, v := range headers[k] {
Expand Down
1 change: 1 addition & 0 deletions main.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
{{- set $opts "fixEmptyArrays" (ternary (in .Opts.fixEmptyArrays "" "true") true false) -}}
{{- set $opts "errorStackTrace" (ternary (in .Opts.errorStackTrace "" "true") true false) -}}
{{- set $opts "legacyErrors" (ternary (in .Opts.legacyErrors "" "true") true false) -}}
{{- set $opts "includeHeaders" (ternary (in .Opts.includeHeaders "" "false") true false) -}}

{{- $typePrefix := (last (split "/" $opts.importTypesFrom)) -}}
{{- if ne $typePrefix "" -}}
Expand Down
2 changes: 1 addition & 1 deletion server.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (s *{{$serviceName}}) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
}()

w.Header().Set(WebRpcHeaderName, WebRpcHeader)
w.Header().Set(WebRpcHeader, WebRpcHeaderValue)

ctx := r.Context()
ctx = context.WithValue(ctx, HTTPResponseWriterCtxKey, w)
Expand Down

0 comments on commit 6dadae4

Please sign in to comment.