This repo contains the templates used by the webrpc-gen
cli to code-generate
webrpc Go server and client code.
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 :)
Change any of the following values by passing -option="Value"
CLI flag to webrpc-gen
.
webrpc-gen -option | Description | Default value |
---|---|---|
-pkg=<name> |
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
CLI option flag | Description |
---|---|
+ go.field.name = ID |
Set custom field name |
+ go.field.type = int64 |
Set custom field type (must be able to JSON unmarshal the value) |
+ 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"`
}
See _examples