Skip to content

Commit

Permalink
rename to WebRpc
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasJenicek committed Oct 7, 2024
1 parent 10705b1 commit d828d4f
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 44 deletions.
30 changes: 15 additions & 15 deletions _examples/golang-basics/example.gen.go

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

30 changes: 15 additions & 15 deletions _examples/golang-imports/api.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 client.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ 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)
req.Header.Set(WebRpcHeaderName, WebRpcHeader)
if headers, ok := HTTPRequestHeaders(ctx); ok {
for k := range headers {
for _, v := range headers[k] {
Expand Down
24 changes: 12 additions & 12 deletions main.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ package {{get $opts "pkg"}}

{{template "imports" dict "Types" .Types "Opts" $opts }}

const WebRPCHeader = "{{ .WebrpcHeader }}"
const WebRpcHeader = "{{ .WebrpcHeader }}"

const WebRPCHeaderName = "Webrpc"
const WebRpcHeaderName = "Webrpc"

// WebRPC description and code-gen version
func WebRPCVersion() string {
Expand All @@ -100,37 +100,37 @@ func WebRPCSchemaHash() string {
return "{{.SchemaHash}}"
}

type WebRPCGenVersions struct {
WebRPCGenVersion string
type WebRpcGenVersions struct {
WebRpcGenVersion string
CodeGenName string
CodeGenVersion string
SchemaName string
SchemaVersion string
}

func ServerVersion() (*WebRPCGenVersions, error) {
versions, err := parseWebRPCGenVersions(WebRPCHeader)
func ServerVersion() (*WebRpcGenVersions, error) {
versions, err := parseWebRpcGenVersions(WebRpcHeader)
if err != nil {
return nil, fmt.Errorf("webrpc header is invalid: %w", err)
}

return versions, nil
}

func VersionFromHeader(h http.Header) (*WebRPCGenVersions, error) {
if h.Get(WebRPCHeaderName) == "" {
func VersionFromHeader(h http.Header) (*WebRpcGenVersions, error) {
if h.Get(WebRpcHeaderName) == "" {
return nil, fmt.Errorf("header is empty or missing")
}

versions, err := parseWebRPCGenVersions(h.Get(WebRPCHeaderName))
versions, err := parseWebRpcGenVersions(h.Get(WebRpcHeaderName))
if err != nil {
return nil, fmt.Errorf("webrpc header is invalid: %w", err)
}

return versions, nil
}

func parseWebRPCGenVersions(header string) (*WebRPCGenVersions, error) {
func parseWebRpcGenVersions(header string) (*WebRpcGenVersions, error) {
versions := strings.Split(header, ";")
if len(versions) < 3 {
return nil, fmt.Errorf("expected at least 3 parts while parsing webrpc header: %v", header)
Expand All @@ -151,8 +151,8 @@ func parseWebRPCGenVersions(header string) (*WebRPCGenVersions, error) {
return nil, fmt.Errorf("schema name and schema version could not be parsed from: %s", versions[2])
}

return &WebRPCGenVersions{
WebRPCGenVersion: webrpcGenVersion,
return &WebRpcGenVersions{
WebRpcGenVersion: webrpcGenVersion,
CodeGenName: tmplTarget,
CodeGenVersion: tmplVersion,
SchemaName: schemaName,
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(WebRpcHeaderName, WebRpcHeader)

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

0 comments on commit d828d4f

Please sign in to comment.