Skip to content

Releases: webrpc/gen-golang

v0.11.3

20 Jul 13:51
895ed7b
Compare
Choose a tag to compare
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

19 Jul 11:29
a8dd70a
Compare
Choose a tag to compare

"go.type.import" meta, which lets you choose an import of the given "go.field.type".

v0.11.1

19 Jul 11:29
a8dd70a
Compare
Choose a tag to compare

Implement -importTypesFrom=<flag> opt flag.

v0.11.0 schema errors (breaking API changes)

23 Mar 11:51
4fb8b9d
Compare
Choose a tag to compare

See full [email protected] release.

[email protected] 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

02 Jan 16:17
152a8f2
Compare
Choose a tag to compare

v0.9.0: Update to [email protected]

28 Dec 18:43
41cd528
Compare
Choose a tag to compare
Update templates to [email protected] schema (#13)

* Require [email protected]

* Update templates to [email protected] JSON schema

* Improve the templates

* Test against https://github.com/webrpc/webrpc/pull/171

* Migrate examples to [email protected]

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`

29 Nov 11:14
9e0555e
Compare
Choose a tag to compare

Tested with [email protected] ✅ .

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

25 Nov 14:53
413586e
Compare
Choose a tag to compare

Requires at least [email protected] (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"`
 }

v0.7.5: Fixes regression in JSON struct field name

19 Nov 13:26
Compare
Choose a tag to compare

Fixes webrpc/webrpc#135

Example:

  1. Given this RIDL
 message User
  - ID: uint64
       + go.tag.db = id
  1. the generated code will result in
 type Nickname struct {
-   ID        uint64     `json:"iD" db:"id"`
+   ID        uint64     `json:"ID" db:"id"`
 }

v0.7.4: Fix methods with no response value

14 Nov 21:23
Compare
Choose a tag to compare

Methods with no response value now render empty JSON object {}.

# RIDL

service ExampleService
  - Ping()
@ func (s *exampleServiceServer) servePingJSON(ctx context.Context, w http.ResponseWriter, r *http.Request) {

    w.Header().Set("Content-Type", "application/json")
    w.WriteHeader(http.StatusOK)
+   w.Write([]byte("{}"))
 }

Fixes webrpc/webrpc#74
Fixes webrpc/webrpc#104
Fixes webrpc/webrpc#105