Go to file
2022-08-17 08:48:21 +02:00
.github/workflows chore: add checks 2022-08-17 07:52:23 +02:00
cmd/gotsrpc fix: fix lint errors 2022-08-17 08:48:21 +02:00
config fix: fix lint errors 2022-08-17 08:48:21 +02:00
example fix: fix lint errors 2022-08-17 08:48:21 +02:00
prometheus fix: fix lint errors 2022-08-17 08:48:21 +02:00
.gitignore feat: ignore node modules 2022-03-02 14:52:09 +01:00
.golangci.yaml fix: fix lint errors 2022-08-17 08:48:21 +02:00
.goreleaser.yml chore: add arm64 2021-12-23 11:50:38 +01:00
build.go fix: fix lint errors 2022-08-17 08:48:21 +02:00
client_test.go feat: add context to go client 2021-05-21 14:42:01 +02:00
client.go fix: fix lint errors 2022-08-17 08:48:21 +02:00
clienterror.go feat: support union types 2022-03-02 15:18:09 +01:00
code.go async client flavor added 2018-06-12 14:09:46 +02:00
error.go fix: fix lint errors 2022-08-17 08:48:21 +02:00
go.go fix: fix lint errors 2022-08-17 08:48:21 +02:00
go.mod feat: bump to go 1.19 2022-08-17 07:49:14 +02:00
go.sum feat: bump to go 1.19 2022-08-17 07:49:14 +02:00
gorpc.go fix: fix go method types 2022-05-19 23:31:58 +02:00
gotsrpc_test.go improved interface{} support and refactored arg loading 2017-07-25 08:46:42 +02:00
gotsrpc.go fix: fix lint errors 2022-08-17 08:48:21 +02:00
http_test.go fix: fix lint errors 2022-08-17 08:48:21 +02:00
http.go fix: fix lint errors 2022-08-17 08:48:21 +02:00
httperror.go feat: support union types 2022-03-02 15:18:09 +01:00
instrumentation_test.go fix: fix lint errors 2022-08-17 08:48:21 +02:00
instrumentation.go feat: add monitor 2022-05-04 11:16:04 +02:00
Makefile fix: fix lint errors 2022-08-17 08:48:21 +02:00
model.go fix: fix lint errors 2022-08-17 08:48:21 +02:00
monitor.go feat: add monitor 2022-05-04 11:16:04 +02:00
README.md feat: replace examples 2022-02-17 14:22:15 +01:00
responsewriter.go feat: don't send reponse on http error 2021-05-21 15:25:09 +02:00
servicereader.go fix: fix lint errors 2022-08-17 08:48:21 +02:00
stats.go feat: add monitor 2022-05-04 11:16:04 +02:00
timeext.go fix: fix lint errors 2022-08-17 08:48:21 +02:00
transport.go fix: fix lint errors 2022-08-17 08:48:21 +02:00
typereader.go fix: fix lint errors 2022-08-17 08:48:21 +02:00
typescript_test.go async client flavor added 2018-06-12 14:09:46 +02:00
typescript.go fix: fix lint errors 2022-08-17 08:48:21 +02:00
typscriptclient.go fix: fix lint errors 2022-08-17 08:48:21 +02:00
unionext.go feat: support union types 2022-03-02 15:18:09 +01:00

Go / TypeScript and Go / Go RPC

Build Status

Installation

From source to /usr/local/bin/gotsrpc:

go get github.com/foomo/gotsrpc/v2
cd $GOPATH/src/github.com/foomo/gotsrpc
make install

If you trust us there are precompiled versions:

releases

On the mac:

brew install foomo/gotsrpc/gotsrpc

Usage

gotsrpc gotsrpc.yml

Will generate client and server side go and TypeScript code. Have fun!

Configuration Examples

targets:
  demo:
    services:
      /service/foo: Foo
      /service/demo: Demo
    package: github.com/foomo/gotsrpc/v2/demo
    out: /tmp/test.ts
    gorpc:
      - Foo
      - Demo
    tsrpc:
      - Foo
      - Demo

mappings:
  github.com/foomo/gotsrpc/v2/demo:
    out: /tmp/test-files-demo.ts
  github.com/foomo/gotsrpc/v2/demo/nested:
    out: /tmp/test-files-demo-nested.ts
...

Async Example

How to use async clients in this case with axios:

import axios, { AxiosResponse } from "axios";
import { ServiceClient as ExampleClient } from "./some/generated/client";

// axios transport
let getTransport = endpoint => async <T>(method, args = []) => {
	return new Promise<T>(async (resolve, reject) => {
		try {
			let axiosPromise: AxiosResponse<T> = await axios.post<T>(
				endpoint + "/" + encodeURIComponent(method),
				JSON.stringify(args),
			);
			return resolve(axiosPromise.data);
		} catch (e) {
			return reject(e);
		}
	});
};

let client = new ExampleClient(getTransport(ExampleClient.defaultEndpoint));

export async function test() {
	try {
		let result = await client.getResult();
		console.log("here is the result", result);
	} catch (e) {
		// e => network?
		// e => json
		// e => domain error type
		console.error("something went wrong ...", e);
	}
}

GOModule Support

To support go modules add


module:
  name: github.com/foomo/gotsrpc
  path: ../ # Relative Or Absolute Path where the package was checked out (root of the package)