Go to file
2018-06-12 14:09:46 +02:00
cmd async client flavor added 2018-06-12 14:09:46 +02:00
config async client flavor added 2018-06-12 14:09:46 +02:00
demo demos updated 2018-06-12 14:05:15 +02:00
prometheus added size to instrumentation 2017-01-27 17:18:23 +01:00
.gitignore Add .idea to gitignore 2017-09-28 11:42:11 +02:00
.goreleaser.yml Add goreleaser for gotsrpc configuration 2017-07-07 14:36:47 +02:00
.travis.yml Update travisfile to only listen to master changes 2017-07-07 15:01:57 +02:00
build.go async client flavor added 2018-06-12 14:09:46 +02:00
client.go added configurable transport 2016-12-14 13:44:16 +01:00
code.go async client flavor added 2018-06-12 14:09:46 +02:00
glide.lock added golang.org/x/tools/imports 2017-10-13 10:39:20 +02:00
glide.yaml added golang.org/x/tools/imports 2017-10-13 10:39:20 +02:00
go.go Add clearStats line to the generated code 2017-11-17 15:22:19 +01:00
gorpc.go fixed types 2016-12-17 15:55:32 +01:00
gotsrpc_test.go improved interface{} support and refactored arg loading 2017-07-25 08:46:42 +02:00
gotsrpc.go Add ClearStats function 2017-11-17 14:50:22 +01:00
Makefile demo Makefile happy again 2017-10-18 15:55:15 +02:00
model.go async client flavor added 2018-06-12 14:09:46 +02:00
php.go Change comment information for gotsrpc to conform to generated file std 2017-09-28 11:43:04 +02:00
reader_test.go improved interface{} support and refactored arg loading 2017-07-25 08:46:42 +02:00
README.md async client flavor added 2018-06-12 14:09:46 +02:00
servicereader.go async client flavor added 2018-06-12 14:09:46 +02:00
stats.go added response and request size to stats 2017-01-27 16:59:03 +01:00
typereader.go async client flavor added 2018-06-12 14:09:46 +02:00
typescript_test.go async client flavor added 2018-06-12 14:09:46 +02:00
typescript.go async client flavor added 2018-06-12 14:09:46 +02:00
typescriptclient.go async client flavor added 2018-06-12 14:09:46 +02:00
typscriptclientasync.go async client flavor added 2018-06-12 14:09:46 +02:00

Go / TypeScript and Go / Go RPC

Installation

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

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

If you trust us there are precompiled versions:

/foomo/gotsrpc/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!

config expamples

commonjs

demo/config.yml

---
modulekind: commonjs
# if you want an async api vs classic callbacks - here you are
tsclientflavor: async
targets:
  demo:
    services:
      /service/foo: Foo
      /service/demo: Demo
    package: github.com/foomo/gotsrpc/demo
    out: /tmp/test.ts
    gorpc:
      - Foo
      - Demo
    tsrpc:
      - Foo
      - Demo

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

an async example

How to use async clients in this case with axios:

import axios, { AxiosPromise } 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: any = 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);
  }
}

oldschool TypeScript

demo/config.yml

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

mappings:
  github.com/foomo/gotsrpc/demo:
    module: GoTSRPC.Demo
    out: /tmp/test-files-demo.ts
  github.com/foomo/gotsrpc/demo/nested:
    module: GoTSRPC.Demo.Nested
    out: /tmp/test-files-demo-nested.ts
...