Skip to content

Commit

Permalink
add client and server versions of generators (webrpc, schema and ridl…
Browse files Browse the repository at this point in the history
… schema)
  • Loading branch information
LukasJenicek committed Oct 7, 2024
1 parent 0ab8431 commit 10705b1
Show file tree
Hide file tree
Showing 8 changed files with 257 additions and 8 deletions.
88 changes: 82 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.

9 changes: 8 additions & 1 deletion _examples/golang-basics/example.ridl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ webrpc = v1 # version of webrpc schema format (ridl or json)

name = example # name of your backend app
version = v0.0.1 # version of your schema


# user role
# which defines which type of operations user can do
Expand Down Expand Up @@ -69,6 +68,8 @@ struct Version
- webrpcVersion: string
- schemaVersion: string
- schemaHash: string
- clientGenVersion: GenVersions
- serverGenVersion: GenVersions

struct ComplexType
- meta: map<string,any>
Expand All @@ -81,6 +82,12 @@ struct ComplexType
- mapOfUsers: map<string,User>
- user: User

struct GenVersions
- WebRPCGenVersion: string
- TmplTarget: string
- TmplVersion: string
- SchemaVersion: string

error 500100 MissingArgument "missing argument"
error 500101 InvalidUsername "invalid username"
error 400100 MemoryFull "system memory is full"
Expand Down
8 changes: 8 additions & 0 deletions _examples/golang-basics/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ func TestStatus(t *testing.T) {
assert.NoError(t, err)
}

func TestVersion(t *testing.T) {
version, err := client.Version(context.Background())

assert.NoError(t, err)
assert.NotNil(t, version.ClientGenVersion)
assert.NotNil(t, version.ServerGenVersion)
}

func TestGetUser(t *testing.T) {
{
arg1 := map[string]string{"a": "1"}
Expand Down
24 changes: 24 additions & 0 deletions _examples/golang-basics/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,34 @@ func (rpc *ExampleServiceRPC) Status(ctx context.Context) (bool, error) {
}

func (rpc *ExampleServiceRPC) Version(ctx context.Context) (*Version, error) {
serverVersions, err := ServerVersion()
if err != nil {
return nil, fmt.Errorf("parse server webrpc gen versions: %w", err)
}

req := RequestFromContext(ctx)

clientVersions, err := VersionFromHeader(req.Header)
if err != nil {
return nil, fmt.Errorf("parse client webrpc gen versions: %w", err)
}

return &Version{
WebrpcVersion: WebRPCVersion(),
SchemaVersion: WebRPCSchemaVersion(),
SchemaHash: WebRPCSchemaHash(),
ClientGenVersion: &GenVersions{
WebRPCGenVersion: clientVersions.WebRPCGenVersion,
TmplTarget: clientVersions.CodeGenName,
TmplVersion: clientVersions.CodeGenVersion,
SchemaVersion: clientVersions.CodeGenVersion,
},
ServerGenVersion: &GenVersions{
WebRPCGenVersion: serverVersions.WebRPCGenVersion,
TmplTarget: serverVersions.CodeGenName,
TmplVersion: serverVersions.CodeGenVersion,
SchemaVersion: serverVersions.CodeGenVersion,
},
}, nil
}

Expand Down
69 changes: 68 additions & 1 deletion _examples/golang-imports/api.gen.go

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

1 change: 1 addition & 0 deletions client.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +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)
if headers, ok := HTTPRequestHeaders(ctx); ok {
for k := range headers {
for _, v := range headers[k] {
Expand Down
Loading

0 comments on commit 10705b1

Please sign in to comment.