Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,28 @@ on:
- "**"

jobs:
build:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19

- name: Test
run: go test -v ./...

examples:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19
- name: Build
run: go install ./cmd/webrpc-gen
- name: Regenerate examples
run: make generate
- name: Git diff of regenerated examples
run: git diff --color --exit-code
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ test: generate

generate:
go generate ./...
@for i in _examples/*/Makefile; do \
echo; echo $$ cd $$i \&\& make generate; \
cd $$(dirname $$i); \
make generate; \
cd ../../; \
done

dep:
@export GO111MODULE=on && go mod tidy
Expand Down
2 changes: 1 addition & 1 deletion _examples/golang-basics/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:generate ../../bin/webrpc-gen -schema=example.ridl -target=go -pkg=main -server -client -out=./example.gen.go
//go:generate webrpc-gen -schema=example.ridl -target=go -pkg=main -server -client -out=./example.gen.go
package main

import (
Expand Down
2 changes: 1 addition & 1 deletion _examples/golang-imports/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:generate ../../bin/webrpc-gen -schema=./proto/api.ridl -target=go -pkg=main -server -client -out=./api.gen.go
//go:generate webrpc-gen -schema=./proto/api.ridl -target=go -pkg=main -server -client -out=./api.gen.go
package main

import (
Expand Down
4 changes: 2 additions & 2 deletions _examples/golang-nodejs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ all:
@echo "please read Makefile source or README to see available commands"

generate:
../../bin/webrpc-gen -schema=example.webrpc.json -target=go -pkg=main -server -out=./server/server.gen.go
../../bin/webrpc-gen -schema=example.webrpc.json -target=js -client -out=./client/client.gen.mjs
webrpc-gen -schema=example.webrpc.json -target=go -pkg=main -server -out=./server/server.gen.go
webrpc-gen -schema=example.webrpc.json -target=js -client -out=./client/client.gen.mjs

run-server:
go run ./server
Expand Down
4 changes: 2 additions & 2 deletions _examples/golang-nodejs/client/client.gen.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// example v0.0.1 07d79ad7e0e7bc2320ac29fdd065307ce932cf47
// example v0.0.1 33aa93c6d912046df938c7f94cef36d3a30679fa
// --
// This file has been generated by https://github.com/webrpc/webrpc using gen/javascript
// Do not edit by hand. Update your webrpc schema and re-generate.
Expand All @@ -10,7 +10,7 @@ export const WebRPCVersion = "v1"
export const WebRPCSchemaVersion = " v0.0.1"

// Schema hash generated from your RIDL schema
export const WebRPCSchemaHash = "07d79ad7e0e7bc2320ac29fdd065307ce932cf47"
export const WebRPCSchemaHash = "33aa93c6d912046df938c7f94cef36d3a30679fa"


//
Expand Down
25 changes: 19 additions & 6 deletions _examples/golang-nodejs/server/server.gen.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// example v0.0.1 07d79ad7e0e7bc2320ac29fdd065307ce932cf47
// example v0.0.1 33aa93c6d912046df938c7f94cef36d3a30679fa
// --
// This file has been generated by https://github.com/webrpc/webrpc using gen/golang
// Do not edit by hand. Update your webrpc schema and re-generate.
Expand Down Expand Up @@ -27,7 +27,7 @@ func WebRPCSchemaVersion() string {

// Schema hash generated from your RIDL schema
func WebRPCSchemaHash() string {
return "07d79ad7e0e7bc2320ac29fdd065307ce932cf47"
return "33aa93c6d912046df938c7f94cef36d3a30679fa"
}

//
Expand Down Expand Up @@ -335,6 +335,14 @@ func WrapError(code ErrorCode, cause error, format string, args ...interface{})
return &rpcErr{code: ErrInternal, msg: "invalid error type " + string(code), cause: cause}
}

func Failf(format string, args ...interface{}) Error {
return Errorf(ErrFail, format, args...)
}

func WrapFailf(cause error, format string, args ...interface{}) Error {
return WrapError(ErrFail, cause, format, args...)
}

func ErrorNotFound(format string, args ...interface{}) Error {
return Errorf(ErrNotFound, format, args...)
}
Expand All @@ -354,13 +362,16 @@ func ErrorInternal(format string, args ...interface{}) Error {
type ErrorCode string

const (
// Canceled indicates the operation was cancelled (typically by the caller).
ErrCanceled ErrorCode = "canceled"

// Unknown error. For example when handling errors raised by APIs that do not
// return enough error information.
ErrUnknown ErrorCode = "unknown"

// Fail error. General failure error type.
ErrFail ErrorCode = "fail"

// Canceled indicates the operation was cancelled (typically by the caller).
ErrCanceled ErrorCode = "canceled"

// InvalidArgument indicates client specified an invalid argument. It
// indicates arguments that are problematic regardless of the state of the
// system (i.e. a malformed file name, required argument, number out of range,
Expand Down Expand Up @@ -449,7 +460,9 @@ func HTTPStatusFromErrorCode(code ErrorCode) int {
case ErrCanceled:
return 408 // RequestTimeout
case ErrUnknown:
return 500 // Internal Server Error
return 400 // Bad Request
case ErrFail:
return 422 // Unprocessable Entity
case ErrInvalidArgument:
return 400 // BadRequest
case ErrDeadlineExceeded:
Expand Down
4 changes: 2 additions & 2 deletions _examples/hello-webrpc-ts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ tools:
generate: generate-server generate-client

generate-server:
../../bin/webrpc-gen -schema=hello-api.ridl -target=go -pkg=main -server -out=./server/hello_api.gen.go
webrpc-gen -schema=hello-api.ridl -target=go -pkg=main -server -out=./server/hello_api.gen.go

generate-client:
../../bin/webrpc-gen -schema=hello-api.ridl -target=ts -client -out=./webapp/src/client.gen.ts
webrpc-gen -schema=hello-api.ridl -target=ts -client -out=./webapp/src/client.gen.ts

bootstrap:
rm -rf webapp/node_modules
Expand Down
25 changes: 19 additions & 6 deletions _examples/hello-webrpc-ts/server/hello_api.gen.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// hello-webrpc v1.0.0 87ce8159bce3ad056518dfb1f1877b1a1012b34d
// hello-webrpc v1.0.0 5ace0c3aa305e464d6a2c180f43e8876be34e155
// --
// This file has been generated by https://github.com/webrpc/webrpc using gen/golang
// Do not edit by hand. Update your webrpc schema and re-generate.
Expand Down Expand Up @@ -27,7 +27,7 @@ func WebRPCSchemaVersion() string {

// Schema hash generated from your RIDL schema
func WebRPCSchemaHash() string {
return "87ce8159bce3ad056518dfb1f1877b1a1012b34d"
return "5ace0c3aa305e464d6a2c180f43e8876be34e155"
}

//
Expand Down Expand Up @@ -400,6 +400,14 @@ func WrapError(code ErrorCode, cause error, format string, args ...interface{})
return &rpcErr{code: ErrInternal, msg: "invalid error type " + string(code), cause: cause}
}

func Failf(format string, args ...interface{}) Error {
return Errorf(ErrFail, format, args...)
}

func WrapFailf(cause error, format string, args ...interface{}) Error {
return WrapError(ErrFail, cause, format, args...)
}

func ErrorNotFound(format string, args ...interface{}) Error {
return Errorf(ErrNotFound, format, args...)
}
Expand All @@ -419,13 +427,16 @@ func ErrorInternal(format string, args ...interface{}) Error {
type ErrorCode string

const (
// Canceled indicates the operation was cancelled (typically by the caller).
ErrCanceled ErrorCode = "canceled"

// Unknown error. For example when handling errors raised by APIs that do not
// return enough error information.
ErrUnknown ErrorCode = "unknown"

// Fail error. General failure error type.
ErrFail ErrorCode = "fail"

// Canceled indicates the operation was cancelled (typically by the caller).
ErrCanceled ErrorCode = "canceled"

// InvalidArgument indicates client specified an invalid argument. It
// indicates arguments that are problematic regardless of the state of the
// system (i.e. a malformed file name, required argument, number out of range,
Expand Down Expand Up @@ -514,7 +525,9 @@ func HTTPStatusFromErrorCode(code ErrorCode) int {
case ErrCanceled:
return 408 // RequestTimeout
case ErrUnknown:
return 500 // Internal Server Error
return 400 // Bad Request
case ErrFail:
return 422 // Unprocessable Entity
case ErrInvalidArgument:
return 400 // BadRequest
case ErrDeadlineExceeded:
Expand Down
12 changes: 6 additions & 6 deletions _examples/hello-webrpc-ts/webapp/src/client.gen.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* tslint:disable */
// hello-webrpc v1.0.0 87ce8159bce3ad056518dfb1f1877b1a1012b34d
/* eslint-disable */
// hello-webrpc v1.0.0 5ace0c3aa305e464d6a2c180f43e8876be34e155
// --
// This file has been generated by https://github.com/webrpc/webrpc using gen/typescript
// Do not edit by hand. Update your webrpc schema and re-generate.
Expand All @@ -11,7 +11,7 @@ export const WebRPCVersion = "v1"
export const WebRPCSchemaVersion = "v1.0.0"

// Schema hash generated from your RIDL schema
export const WebRPCSchemaHash = "87ce8159bce3ad056518dfb1f1877b1a1012b34d"
export const WebRPCSchemaHash = "5ace0c3aa305e464d6a2c180f43e8876be34e155"


//
Expand Down Expand Up @@ -69,9 +69,9 @@ export interface FindUsersReturn {
// Client
//
export class ExampleService implements ExampleService {
private hostname: string
private fetch: Fetch
private path = '/rpc/ExampleService/'
protected hostname: string
protected fetch: Fetch
protected path = '/rpc/ExampleService/'

constructor(hostname: string, fetch: Fetch) {
this.hostname = hostname
Expand Down
4 changes: 2 additions & 2 deletions _examples/hello-webrpc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ tools:
generate: generate-server generate-client

generate-server:
../../bin/webrpc-gen -schema=hello-api.ridl -target=go -pkg=main -server -out=./server/hello_api.gen.go
webrpc-gen -schema=hello-api.ridl -target=go -pkg=main -server -out=./server/hello_api.gen.go

generate-client:
../../bin/webrpc-gen -schema=hello-api.ridl -target=js -extra=noexports -client -out=./webapp/client.gen.js
webrpc-gen -schema=hello-api.ridl -target=js -extra=noexports -client -out=./webapp/client.gen.js

run-server:
go run ./server
Expand Down
25 changes: 19 additions & 6 deletions _examples/hello-webrpc/server/hello_api.gen.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// hello-webrpc v1.0.0 c929128d878e94653f3a856f80c4671008e22a45
// hello-webrpc v1.0.0 d12378d7d88e036c2e5f779db475e7144b638b26
// --
// This file has been generated by https://github.com/webrpc/webrpc using gen/golang
// Do not edit by hand. Update your webrpc schema and re-generate.
Expand Down Expand Up @@ -27,7 +27,7 @@ func WebRPCSchemaVersion() string {

// Schema hash generated from your RIDL schema
func WebRPCSchemaHash() string {
return "c929128d878e94653f3a856f80c4671008e22a45"
return "d12378d7d88e036c2e5f779db475e7144b638b26"
}

//
Expand Down Expand Up @@ -319,6 +319,14 @@ func WrapError(code ErrorCode, cause error, format string, args ...interface{})
return &rpcErr{code: ErrInternal, msg: "invalid error type " + string(code), cause: cause}
}

func Failf(format string, args ...interface{}) Error {
return Errorf(ErrFail, format, args...)
}

func WrapFailf(cause error, format string, args ...interface{}) Error {
return WrapError(ErrFail, cause, format, args...)
}

func ErrorNotFound(format string, args ...interface{}) Error {
return Errorf(ErrNotFound, format, args...)
}
Expand All @@ -338,13 +346,16 @@ func ErrorInternal(format string, args ...interface{}) Error {
type ErrorCode string

const (
// Canceled indicates the operation was cancelled (typically by the caller).
ErrCanceled ErrorCode = "canceled"

// Unknown error. For example when handling errors raised by APIs that do not
// return enough error information.
ErrUnknown ErrorCode = "unknown"

// Fail error. General failure error type.
ErrFail ErrorCode = "fail"

// Canceled indicates the operation was cancelled (typically by the caller).
ErrCanceled ErrorCode = "canceled"

// InvalidArgument indicates client specified an invalid argument. It
// indicates arguments that are problematic regardless of the state of the
// system (i.e. a malformed file name, required argument, number out of range,
Expand Down Expand Up @@ -433,7 +444,9 @@ func HTTPStatusFromErrorCode(code ErrorCode) int {
case ErrCanceled:
return 408 // RequestTimeout
case ErrUnknown:
return 500 // Internal Server Error
return 400 // Bad Request
case ErrFail:
return 422 // Unprocessable Entity
case ErrInvalidArgument:
return 400 // BadRequest
case ErrDeadlineExceeded:
Expand Down
4 changes: 2 additions & 2 deletions _examples/hello-webrpc/webapp/client.gen.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// hello-webrpc v1.0.0 c929128d878e94653f3a856f80c4671008e22a45
// hello-webrpc v1.0.0 d12378d7d88e036c2e5f779db475e7144b638b26
// --
// This file has been generated by https://github.com/webrpc/webrpc using gen/javascript
// Do not edit by hand. Update your webrpc schema and re-generate.
Expand All @@ -10,7 +10,7 @@ export const WebRPCVersion = "v1"
export const WebRPCSchemaVersion = "v1.0.0"

// Schema hash generated from your RIDL schema
export const WebRPCSchemaHash = "c929128d878e94653f3a856f80c4671008e22a45"
export const WebRPCSchemaHash = "d12378d7d88e036c2e5f779db475e7144b638b26"


//
Expand Down
4 changes: 2 additions & 2 deletions _examples/node-ts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ bootstrap:
cd webapp && yarn

generate:
../../bin/webrpc-gen -schema=service.ridl -target=ts -server -out=./server/server.gen.ts
../../bin/webrpc-gen -schema=service.ridl -target=ts -client -out=./webapp/client.gen.ts
webrpc-gen -schema=service.ridl -target=ts -server -out=./server/server.gen.ts
webrpc-gen -schema=service.ridl -target=ts -client -out=./webapp/client.gen.ts

run-server:
yarn --cwd ./server start
Expand Down
6 changes: 3 additions & 3 deletions _examples/node-ts/server/server.gen.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* tslint:disable */
// node-ts v1.0.0 4d2858fa129683e5775e9b863ceceb740e7e09b1
/* eslint-disable */
// node-ts v1.0.0 ecee5cfb3e360bc0bc632e78556b19a2c58d4e25
// --
// This file has been generated by https://github.com/webrpc/webrpc using gen/typescript
// Do not edit by hand. Update your webrpc schema and re-generate.
Expand All @@ -11,7 +11,7 @@ export const WebRPCVersion = "v1"
export const WebRPCSchemaVersion = "v1.0.0"

// Schema hash generated from your RIDL schema
export const WebRPCSchemaHash = "4d2858fa129683e5775e9b863ceceb740e7e09b1"
export const WebRPCSchemaHash = "ecee5cfb3e360bc0bc632e78556b19a2c58d4e25"


//
Expand Down
12 changes: 6 additions & 6 deletions _examples/node-ts/webapp/client.gen.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* tslint:disable */
// node-ts v1.0.0 4d2858fa129683e5775e9b863ceceb740e7e09b1
/* eslint-disable */
// node-ts v1.0.0 ecee5cfb3e360bc0bc632e78556b19a2c58d4e25
// --
// This file has been generated by https://github.com/webrpc/webrpc using gen/typescript
// Do not edit by hand. Update your webrpc schema and re-generate.
Expand All @@ -11,7 +11,7 @@ export const WebRPCVersion = "v1"
export const WebRPCSchemaVersion = "v1.0.0"

// Schema hash generated from your RIDL schema
export const WebRPCSchemaHash = "4d2858fa129683e5775e9b863ceceb740e7e09b1"
export const WebRPCSchemaHash = "ecee5cfb3e360bc0bc632e78556b19a2c58d4e25"


//
Expand Down Expand Up @@ -61,9 +61,9 @@ export interface GetUserReturn {
// Client
//
export class ExampleService implements ExampleService {
private hostname: string
private fetch: Fetch
private path = '/rpc/ExampleService/'
protected hostname: string
protected fetch: Fetch
protected path = '/rpc/ExampleService/'

constructor(hostname: string, fetch: Fetch) {
this.hostname = hostname
Expand Down