Releases: webrpc/gen-golang
v0.12.0
Implement faster JSON (un)marshaling via jsoniter pkg (#24)
webrpc-gen -schema=proto.ridl -target=golang -client -json=jsoniter -out=client.gen.go
Fixes webrpc/webrpc#20
v0.11.4
Fix uppercase method input/return arguments in server code too (#23) Follow up for #22. This change matches the TypeScript generator: https://github.com/webrpc/gen-typescript/blob/master/types.go.tmpl#L51-L63 Given the following schema: service ExampleService - GetUser(UserID: uint64) => (USER: User) The golang generator wrongly generated "userID" and "uSER" arguments over JSON.
v0.11.3
Fix uppercase method input/return arguments (#22) This change matches the TypeScript generator: https://github.com/webrpc/gen-typescript/blob/master/types.go.tmpl#L51-L63 Given the following schema: service ExampleService - GetUser(UserID: uint64) => (USER: User) The golang generator wrongly generated "userID" and "uSER" arguments over JSON.
v0.11.2
"go.type.import" meta, which lets you choose an import of the given "go.field.type".
v0.11.1
Implement -importTypesFrom=<flag>
opt flag.
v0.11.0 schema errors (breaking API changes)
- Tested with webrpc-gen@v0.11.0 ✅
See full webrpc@v0.11.0 release.
golang@v0.11.0 breaking changes
Note: You can turn on -legacyErrors=true
flag on golang generator (ie. webrpc-gen -target=golang -legacyErrors=true -pkg=proto
) in order to preserve the deprecated functions and sentinel errors (see below). This will allow you to migrate your codebase to the new custom schema errors gradually.
The following werbrpc error functions and sentinel errors are now deprecated or removed:
proto.WrapError() // Deprecated.
proto.Errorf() // Deprecated.
proto.HTTPStatusFromErrorCode()
proto.IsErrorCode()
proto.ErrCanceled // Deprecated.
proto.ErrUnknown // Deprecated.
proto.ErrFail // Deprecated.
proto.ErrInvalidArgument // Deprecated.
proto.ErrDeadlineExceeded // Deprecated.
proto.ErrNotFound // Deprecated.
proto.ErrBadRoute // Deprecated.
proto.ErrAlreadyExists // Deprecated.
proto.ErrPermissionDenied // Deprecated.
proto.ErrUnauthenticated // Deprecated.
proto.ErrResourceExhausted // Deprecated.
proto.ErrFailedPrecondition // Deprecated.
proto.ErrAborted // Deprecated.
proto.ErrOutOfRange // Deprecated.
proto.ErrUnimplemented // Deprecated.
proto.ErrInternal // Deprecated.
proto.ErrUnavailable // Deprecated.
proto.ErrDataLoss // Deprecated.
proto.ErrNone // Deprecated.
The schema errors can now be returned from the RPC endpoints via:
func (s *RPC) RemoveUser(ctx context.Context, userID int64) (bool, error) {
r, _ := ctx.Value(proto.HTTPRequestCtxKey).(*http.Request)
if s.IsRateLimited(r) {
- return false, proto.Errorf(proto.ErrUnavailable, "rate limited")
+ return false, proto.ErrRateLimited // HTTP 429 per RIDL schema
}
_, err := s.DB.RemoveUser(ctx, userID)
if err != nil {
if errors.Is(err, pgx.ErrNoRows) {
- return false, proto.Errorf(proto.ErrNotFound, "no such user(%v)", userID)
+ return false, proto.ErrUserNotFound
}
- return false, proto.WrapError(proto.ErrInternal, err, "")
+ return false, proto.ErrorWithCause(proto.ErrDatabaseDown, err)
}
return true, nil
}
You can also return any other Go error and webrpc will render generic proto.ErrWebrpcEndpoint
error automatically along with HTTP 400
status code.
return fmt.Errorf("some error")
The RPC client(s) can now assert the schema error type by their unique error code:
if err, ok := rpc.RemoveUser(ctx, userID); err != nil {
if errors.Is(proto.ErrRateLimited) {
// slow down; retry with back-off strategy
}
if errors.Is(proto.ErrUserNotFound) {
// handle
}
// etc.
}
v0.10.0: Interoperability tests
- Tested with webrpc-gen@v0.10.0 ✅
- Implemented interoperability tests https://github.com/webrpc/gen-golang/tree/master/tests
v0.9.0: Update to webrpc@v0.9.0
Update templates to webrpc@v0.9.0 schema (#13) * Require webrpc@v0.9.0 * Update templates to webrpc@v0.9.0 JSON schema * Improve the templates * Test against https://github.com/webrpc/webrpc/pull/171 * Migrate examples to webrpc@v0.9.0 find . -name '*.ridl' -exec sed -i -e 's/^message /struct /g' {} \; * Fix template codegen * Regenerate examples * Examples: Use local templates
v0.8.1: Fixes bug with `go.tag.json`
Tested with webrpc-gen@v0.8.0 ✅ .
Fixes bug with go.tag.json
, which rendered duplicated json
tags:
- CreatedAt *time.Time `json:"createdAt" db:"created_at,omitempty" json:"createdAt,omitempty"`
+ UpdatedAt *time.Time `json:"updatedAt,omitempty" db:"updated_at,omitempty"`
v0.8.0: Fixes custom struct tags
Requires at least webrpc-gen@v0.8.0 (new array/sort/append template functions) ✅
This RIDL
message User
- id: uint64
+ go.tag.db = id,omitempty
+ go.tag.cbor = id,omitempty
now correctly generates
type User struct {
- ID uint64 `json:"id" db:"id,omitempty"`
+ ID uint64 `json:"id" db:"id,omitempty" cbor:"id,omitempty"`
}