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 5eeffb4
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 54 deletions.
36 changes: 18 additions & 18 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/example.ridl
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ struct ComplexType
- user: User

struct GenVersions
- WebRPCGenVersion: string
- WebRpcGenVersion: string
- TmplTarget: string
- TmplVersion: string
- SchemaVersion: string
Expand Down
4 changes: 2 additions & 2 deletions _examples/golang-basics/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ func (rpc *ExampleServiceRPC) Version(ctx context.Context) (*Version, error) {
SchemaVersion: WebRPCSchemaVersion(),
SchemaHash: WebRPCSchemaHash(),
ClientGenVersion: &GenVersions{
WebRPCGenVersion: clientVersions.WebRPCGenVersion,
WebRpcGenVersion: clientVersions.WebRpcGenVersion,
TmplTarget: clientVersions.CodeGenName,
TmplVersion: clientVersions.CodeGenVersion,
SchemaVersion: clientVersions.CodeGenVersion,
},
ServerGenVersion: &GenVersions{
WebRPCGenVersion: serverVersions.WebRPCGenVersion,
WebRpcGenVersion: serverVersions.WebRpcGenVersion,
TmplTarget: serverVersions.CodeGenName,
TmplVersion: serverVersions.CodeGenVersion,
SchemaVersion: serverVersions.CodeGenVersion,
Expand Down
34 changes: 17 additions & 17 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
28 changes: 14 additions & 14 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 @@ -148,11 +148,11 @@ func parseWebRPCGenVersions(header string) (*WebRPCGenVersions, error) {

schemaName, schemaVersion, ok := strings.Cut(versions[2], "@")
if !ok {
return nil, fmt.Errorf("schema name and schema version could not be parsed from: %s", versions[2])
}
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 5eeffb4

Please sign in to comment.