webrpc-gen Golang templates
This repo contains the templates used by the webrpc-gen
cli to code-generate webrpc Go server and client code.
Usage
webrpc-gen -schema=example.ridl -target=golang -out=./example.gen.go -Pkg=main -Server -Client
# or
webrpc-gen -schema=example.ridl -target=github.com/webrpc/[email protected] -out=./example.gen.go -Pkg=main -Server -Client
# or
webrpc-gen -schema=example.ridl -target=./local-go-templates-on-disk -out=./example.gen.go -Pkg=main -Server -Client
As you can see, the -target
supports default golang
, any git URI, or a local folder :)
Set custom template variables
Change any of the following values by passing -Option="Value"
CLI flag to webrpc-gen
.
CLI option flag | Description | Default value |
---|---|---|
-Pkg=pkgname |
package name | "proto" |
-Client |
generate client code | unset (false) |
-Server |
generate server code | unset (false) |
Example:
webrpc-gen -schema=./proto.json -target=golang -out openapi.gen.yaml -Pkg=main -Client -Server
Set custom Go field meta tags in your RIDL file
CLI option flag | Description |
---|---|
+ go.field.name = ID |
Set custom field name |
+ go.tag.json = id |
Set json:"id" struct tag |
+ go.tag.db = id |
Set db:"id" struct tag |
Example:
message User
- id: uint64
+ go.field.name = ID
+ go.tag.db = id
+ go.tag.json = id
will result in
type User struct {
ID uint64 `json:"id" db:"id"`
}
Examples
See _examples
Interoperability tests
Interoperability tests
This PR implements webrpc interoperability tests.
Self-test
The basic interoperability unit test is ensuring that the client and server code generated from this repository can talk to each other.
Test matrix against webrpc-test reference binary
These tests are ensuring that
webrpc-test@version
serverwebrpc-test@version
client testswebrpc-test
reference binaries via test.sh scriptFix duplicated json struct tag
Fixes bug with
go.tag.json
, which rendered duplicatedjson
tags:Support custom struct tags (+ go.tag.TAGNAME)
This RIDL
should generate
Fix more optional field regressions
Fixed more edge cases against a proprietary RIDL file to make sure the golang target is fully backward compatible with v0.6.0. These edge cases were not really covered by
./_examples
or tests.Support go.field.type meta
Seems like I might have missed support for
go.field.type
during the webrpc 0.7.0 developmentSee the original code at https://github.com/webrpc/gen-golang/commit/afb0cde87948eaf5656f212ba7f9579cb0fb9d2c
go.field.type
to examplesprototyp.BigInt
Custom type in method argument fails to render
generates wrong server method signature