mirror of
https://github.com/foomo/gotsrpc.git
synced 2025-10-16 12:35:35 +00:00
demos updated
This commit is contained in:
parent
65a84e9cb9
commit
dcc105e15f
23
demo/config-commonjs-async.yml
Normal file
23
demo/config-commonjs-async.yml
Normal file
@ -0,0 +1,23 @@
|
||||
---
|
||||
modulekind: commonjs
|
||||
tsclientflavor: async
|
||||
targets:
|
||||
demo:
|
||||
services:
|
||||
/service/foo: Foo
|
||||
/service/demo: Demo
|
||||
package: github.com/foomo/gotsrpc/demo
|
||||
out: demo/output-commonjs-async/client.ts
|
||||
gorpc:
|
||||
- Foo
|
||||
- Demo
|
||||
tsrpc:
|
||||
- Foo
|
||||
- Demo
|
||||
|
||||
mappings:
|
||||
github.com/foomo/gotsrpc/demo:
|
||||
out: demo/output-commonjs-async/demo.ts
|
||||
github.com/foomo/gotsrpc/demo/nested:
|
||||
out: demo/output-commonjs-async/demo-nested.ts
|
||||
...
|
||||
14
demo/demo.go
14
demo/demo.go
@ -4,6 +4,16 @@ type Err struct {
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
func (e *Err) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
type ScalarError string
|
||||
|
||||
func (se *ScalarError) Error() string {
|
||||
return string(*se)
|
||||
}
|
||||
|
||||
type ScalarInPlace string
|
||||
|
||||
type Demo struct {
|
||||
@ -21,6 +31,10 @@ func (d *Demo) HelloInterface(anything interface{}, anythingMap map[string]inter
|
||||
|
||||
}
|
||||
|
||||
func (d *Demo) HelloScalarError() (err *ScalarError) {
|
||||
return
|
||||
}
|
||||
|
||||
func (d *Demo) nothingInNothinOut() {
|
||||
|
||||
}
|
||||
|
||||
@ -131,6 +131,12 @@ type (
|
||||
DemoHelloInterfaceResponse struct {
|
||||
}
|
||||
|
||||
DemoHelloScalarErrorRequest struct {
|
||||
}
|
||||
DemoHelloScalarErrorResponse struct {
|
||||
Err *ScalarError
|
||||
}
|
||||
|
||||
DemoMapCrapRequest struct {
|
||||
}
|
||||
DemoMapCrapResponse struct {
|
||||
@ -159,6 +165,8 @@ func init() {
|
||||
gob.Register(DemoHelloResponse{})
|
||||
gob.Register(DemoHelloInterfaceRequest{})
|
||||
gob.Register(DemoHelloInterfaceResponse{})
|
||||
gob.Register(DemoHelloScalarErrorRequest{})
|
||||
gob.Register(DemoHelloScalarErrorResponse{})
|
||||
gob.Register(DemoMapCrapRequest{})
|
||||
gob.Register(DemoMapCrapResponse{})
|
||||
gob.Register(DemoNestRequest{})
|
||||
@ -220,6 +228,9 @@ func (p *DemoGoRPCProxy) handler(clientAddr string, request interface{}) (respon
|
||||
req := request.(DemoHelloInterfaceRequest)
|
||||
p.service.HelloInterface(req.Anything, req.AnythingMap, req.AnythingSlice)
|
||||
response = DemoHelloInterfaceResponse{}
|
||||
case "DemoHelloScalarErrorRequest":
|
||||
err := p.service.HelloScalarError()
|
||||
response = DemoHelloScalarErrorResponse{Err: err}
|
||||
case "DemoMapCrapRequest":
|
||||
crap := p.service.MapCrap()
|
||||
response = DemoMapCrapResponse{Crap: crap}
|
||||
|
||||
@ -106,6 +106,17 @@ func (goTSRPCClientInstance *DemoGoRPCClient) HelloInterface(anything interface{
|
||||
return nil
|
||||
}
|
||||
|
||||
func (goTSRPCClientInstance *DemoGoRPCClient) HelloScalarError() (err *ScalarError, clientErr error) {
|
||||
req := DemoHelloScalarErrorRequest{}
|
||||
rpcCallRes, rpcCallErr := goTSRPCClientInstance.Client.Call(req)
|
||||
if rpcCallErr != nil {
|
||||
clientErr = rpcCallErr
|
||||
return
|
||||
}
|
||||
response := rpcCallRes.(DemoHelloScalarErrorResponse)
|
||||
return response.Err, nil
|
||||
}
|
||||
|
||||
func (goTSRPCClientInstance *DemoGoRPCClient) MapCrap() (crap map[string][]int, clientErr error) {
|
||||
req := DemoMapCrapRequest{}
|
||||
rpcCallRes, rpcCallErr := goTSRPCClientInstance.Client.Call(req)
|
||||
|
||||
@ -73,6 +73,7 @@ func (p *FooGoTSRPCProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
gotsrpc.Reply([]interface{}{helloRet}, callStats, r, w)
|
||||
return
|
||||
default:
|
||||
gotsrpc.ClearStats(r)
|
||||
http.Error(w, "404 - not found "+r.URL.Path, http.StatusNotFound)
|
||||
}
|
||||
}
|
||||
@ -185,6 +186,14 @@ func (p *DemoGoTSRPCProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
gotsrpc.Reply([]interface{}{}, callStats, r, w)
|
||||
return
|
||||
case "HelloScalarError":
|
||||
executionStart := time.Now()
|
||||
helloScalarErrorErr := p.service.HelloScalarError()
|
||||
if callStats != nil {
|
||||
callStats.Execution = time.Now().Sub(executionStart)
|
||||
}
|
||||
gotsrpc.Reply([]interface{}{helloScalarErrorErr}, callStats, r, w)
|
||||
return
|
||||
case "MapCrap":
|
||||
executionStart := time.Now()
|
||||
mapCrapCrap := p.service.MapCrap()
|
||||
@ -210,6 +219,7 @@ func (p *DemoGoTSRPCProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
gotsrpc.Reply([]interface{}{testScalarInPlaceRet}, callStats, r, w)
|
||||
return
|
||||
default:
|
||||
gotsrpc.ClearStats(r)
|
||||
http.Error(w, "404 - not found "+r.URL.Path, http.StatusNotFound)
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,6 +73,13 @@ func (goTSRPCClientInstance *DemoGoTSRPCClient) HelloInterface(anything interfac
|
||||
return
|
||||
}
|
||||
|
||||
func (goTSRPCClientInstance *DemoGoTSRPCClient) HelloScalarError() (err *ScalarError, clientErr error) {
|
||||
args := []interface{}{}
|
||||
reply := []interface{}{&err}
|
||||
clientErr = gotsrpc.CallClient(goTSRPCClientInstance.URL, goTSRPCClientInstance.EndPoint, "HelloScalarError", args, reply)
|
||||
return
|
||||
}
|
||||
|
||||
func (goTSRPCClientInstance *DemoGoTSRPCClient) MapCrap() (crap map[string][]int, clientErr error) {
|
||||
args := []interface{}{}
|
||||
reply := []interface{}{&crap}
|
||||
|
||||
54
demo/output-commonjs-async/client.ts
Normal file
54
demo/output-commonjs-async/client.ts
Normal file
@ -0,0 +1,54 @@
|
||||
/* tslint:disable */
|
||||
// hello commonjs - we need some imports - sorted in alphabetical order, by go package
|
||||
import * as github_com_foomo_gotsrpc_demo from './demo'; // demo/output-commonjs-async/client.ts to demo/output-commonjs-async/demo.ts
|
||||
import * as github_com_foomo_gotsrpc_demo_nested from './demo-nested'; // demo/output-commonjs-async/client.ts to demo/output-commonjs-async/demo-nested.ts
|
||||
|
||||
export class FooClient {
|
||||
public static defaultEndpoint = "/service/foo";
|
||||
constructor(
|
||||
public transport:<T>(method: string, data?: any[]) => Promise<T>
|
||||
) {}
|
||||
async hello(number:number):Promise<number> {
|
||||
return (await this.transport<{0:number}>("Hello", [number]))[0]
|
||||
}
|
||||
}
|
||||
export class DemoClient {
|
||||
public static defaultEndpoint = "/service/demo";
|
||||
constructor(
|
||||
public transport:<T>(method: string, data?: any[]) => Promise<T>
|
||||
) {}
|
||||
async extractAddress(person:github_com_foomo_gotsrpc_demo.Person):Promise<github_com_foomo_gotsrpc_demo.Address> {
|
||||
let response = await this.transport<{0:github_com_foomo_gotsrpc_demo.Address; 1:github_com_foomo_gotsrpc_demo.Err}>("ExtractAddress", [person])
|
||||
let err = response[1];
|
||||
if(err) { throw err }
|
||||
return response[0]
|
||||
}
|
||||
async giveMeAScalar():Promise<{amount:number; wahr:boolean; hier:string}> {
|
||||
let response = await this.transport<{0:number; 1:boolean; 2:string}>("GiveMeAScalar", [])
|
||||
let responseObject = {amount : response[0], wahr : response[1], hier : response[2]};
|
||||
return responseObject;
|
||||
}
|
||||
async hello(name:string):Promise<string> {
|
||||
let response = await this.transport<{0:string; 1:github_com_foomo_gotsrpc_demo.Err}>("Hello", [name])
|
||||
let err = response[1];
|
||||
if(err) { throw err }
|
||||
return response[0]
|
||||
}
|
||||
async helloInterface(anything:any, anythingMap:{[index:string]:any}, anythingSlice:any[]):Promise<void> {
|
||||
let response = await this.transport<void>("HelloInterface", [anything, anythingMap, anythingSlice])
|
||||
let responseObject = {};
|
||||
return responseObject;
|
||||
}
|
||||
async helloScalarError():Promise<string> {
|
||||
return (await this.transport<{0:string}>("HelloScalarError", []))[0]
|
||||
}
|
||||
async mapCrap():Promise<{[index:string]:number[]}> {
|
||||
return (await this.transport<{0:{[index:string]:number[]}}>("MapCrap", []))[0]
|
||||
}
|
||||
async nest():Promise<github_com_foomo_gotsrpc_demo_nested.Nested> {
|
||||
return (await this.transport<{0:github_com_foomo_gotsrpc_demo_nested.Nested}>("Nest", []))[0]
|
||||
}
|
||||
async testScalarInPlace():Promise<string> {
|
||||
return (await this.transport<{0:string}>("TestScalarInPlace", []))[0]
|
||||
}
|
||||
}
|
||||
15
demo/output-commonjs-async/demo-nested.ts
Normal file
15
demo/output-commonjs-async/demo-nested.ts
Normal file
@ -0,0 +1,15 @@
|
||||
/* tslint:disable */
|
||||
// hello commonjs - we need some imports - sorted in alphabetical order, by go package
|
||||
import * as github_com_foomo_gotsrpc_demo from './demo'; // demo/output-commonjs-async/demo-nested.ts to demo/output-commonjs-async/demo.ts
|
||||
import * as github_com_foomo_gotsrpc_demo_nested from './demo-nested'; // demo/output-commonjs-async/demo-nested.ts to demo/output-commonjs-async/demo-nested.ts
|
||||
// github.com/foomo/gotsrpc/demo/nested.Nested
|
||||
export interface Nested {
|
||||
Name:string;
|
||||
SuperNestedString:{
|
||||
Ha:number;
|
||||
};
|
||||
SuperNestedPtr?:{
|
||||
Bla:string;
|
||||
};
|
||||
}
|
||||
// end of common js
|
||||
35
demo/output-commonjs-async/demo.ts
Normal file
35
demo/output-commonjs-async/demo.ts
Normal file
@ -0,0 +1,35 @@
|
||||
/* tslint:disable */
|
||||
// hello commonjs - we need some imports - sorted in alphabetical order, by go package
|
||||
import * as github_com_foomo_gotsrpc_demo from './demo'; // demo/output-commonjs-async/demo.ts to demo/output-commonjs-async/demo.ts
|
||||
import * as github_com_foomo_gotsrpc_demo_nested from './demo-nested'; // demo/output-commonjs-async/demo.ts to demo/output-commonjs-async/demo-nested.ts
|
||||
// github.com/foomo/gotsrpc/demo.Address
|
||||
export interface Address {
|
||||
city?:string;
|
||||
signs?:string[];
|
||||
PeoplePtr:github_com_foomo_gotsrpc_demo.Person[];
|
||||
ArrayOfMaps:{[index:string]:boolean}[];
|
||||
ArrayArrayAddress:github_com_foomo_gotsrpc_demo.Address[][];
|
||||
People:github_com_foomo_gotsrpc_demo.Person[];
|
||||
MapCrap:{[index:string]:{[index:number]:boolean}};
|
||||
NestedPtr?:github_com_foomo_gotsrpc_demo_nested.Nested;
|
||||
NestedStruct:github_com_foomo_gotsrpc_demo_nested.Nested;
|
||||
}
|
||||
// github.com/foomo/gotsrpc/demo.Err
|
||||
export interface Err {
|
||||
message:string;
|
||||
}
|
||||
// github.com/foomo/gotsrpc/demo.Person
|
||||
export interface Person {
|
||||
Name:string;
|
||||
address?:github_com_foomo_gotsrpc_demo.Address;
|
||||
AddressStruct:github_com_foomo_gotsrpc_demo.Address;
|
||||
Addresses:{[index:string]:github_com_foomo_gotsrpc_demo.Address};
|
||||
InlinePtr?:{
|
||||
Foo:boolean;
|
||||
};
|
||||
InlineStruct:{
|
||||
Bar:string;
|
||||
};
|
||||
DNA:string;
|
||||
}
|
||||
// end of common js
|
||||
@ -23,6 +23,9 @@ export class DemoClient {
|
||||
helloInterface(anything:any, anythingMap:{[index:string]:any}, anythingSlice:any[], success:() => void, err:(request:XMLHttpRequest, e?:Error) => void) {
|
||||
this.transport(this.endPoint, "HelloInterface", [anything, anythingMap, anythingSlice], success, err);
|
||||
}
|
||||
helloScalarError(success:(err:string) => void, err:(request:XMLHttpRequest, e?:Error) => void) {
|
||||
this.transport(this.endPoint, "HelloScalarError", [], success, err);
|
||||
}
|
||||
mapCrap(success:(crap:{[index:string]:number[]}) => void, err:(request:XMLHttpRequest, e?:Error) => void) {
|
||||
this.transport(this.endPoint, "MapCrap", [], success, err);
|
||||
}
|
||||
|
||||
@ -2,14 +2,14 @@
|
||||
// hello commonjs - we need some imports - sorted in alphabetical order, by go package
|
||||
import * as github_com_foomo_gotsrpc_demo from './demo'; // demo/output-commonjs/demo-nested.ts to demo/output-commonjs/demo.ts
|
||||
import * as github_com_foomo_gotsrpc_demo_nested from './demo-nested'; // demo/output-commonjs/demo-nested.ts to demo/output-commonjs/demo-nested.ts
|
||||
// github.com/foomo/gotsrpc/demo/nested.Nested
|
||||
export interface Nested {
|
||||
Name:string;
|
||||
SuperNestedString:{
|
||||
Ha:number;
|
||||
};
|
||||
SuperNestedPtr?:{
|
||||
Bla:string;
|
||||
};
|
||||
}
|
||||
// github.com/foomo/gotsrpc/demo/nested.Nested
|
||||
export interface Nested {
|
||||
Name:string;
|
||||
SuperNestedString:{
|
||||
Ha:number;
|
||||
};
|
||||
SuperNestedPtr?:{
|
||||
Bla:string;
|
||||
};
|
||||
}
|
||||
// end of common js
|
||||
@ -2,34 +2,34 @@
|
||||
// hello commonjs - we need some imports - sorted in alphabetical order, by go package
|
||||
import * as github_com_foomo_gotsrpc_demo from './demo'; // demo/output-commonjs/demo.ts to demo/output-commonjs/demo.ts
|
||||
import * as github_com_foomo_gotsrpc_demo_nested from './demo-nested'; // demo/output-commonjs/demo.ts to demo/output-commonjs/demo-nested.ts
|
||||
// github.com/foomo/gotsrpc/demo.Address
|
||||
export interface Address {
|
||||
city?:string;
|
||||
signs?:string[];
|
||||
PeoplePtr:github_com_foomo_gotsrpc_demo.Person[];
|
||||
ArrayOfMaps:{[index:string]:boolean}[];
|
||||
ArrayArrayAddress:github_com_foomo_gotsrpc_demo.Address[][];
|
||||
People:github_com_foomo_gotsrpc_demo.Person[];
|
||||
MapCrap:{[index:string]:{[index:number]:boolean}};
|
||||
NestedPtr?:github_com_foomo_gotsrpc_demo_nested.Nested;
|
||||
NestedStruct:github_com_foomo_gotsrpc_demo_nested.Nested;
|
||||
}
|
||||
// github.com/foomo/gotsrpc/demo.Err
|
||||
export interface Err {
|
||||
message:string;
|
||||
}
|
||||
// github.com/foomo/gotsrpc/demo.Person
|
||||
export interface Person {
|
||||
Name:string;
|
||||
address?:github_com_foomo_gotsrpc_demo.Address;
|
||||
AddressStruct:github_com_foomo_gotsrpc_demo.Address;
|
||||
Addresses:{[index:string]:github_com_foomo_gotsrpc_demo.Address};
|
||||
InlinePtr?:{
|
||||
Foo:boolean;
|
||||
};
|
||||
InlineStruct:{
|
||||
Bar:string;
|
||||
};
|
||||
DNA:string;
|
||||
}
|
||||
// github.com/foomo/gotsrpc/demo.Address
|
||||
export interface Address {
|
||||
city?:string;
|
||||
signs?:string[];
|
||||
PeoplePtr:github_com_foomo_gotsrpc_demo.Person[];
|
||||
ArrayOfMaps:{[index:string]:boolean}[];
|
||||
ArrayArrayAddress:github_com_foomo_gotsrpc_demo.Address[][];
|
||||
People:github_com_foomo_gotsrpc_demo.Person[];
|
||||
MapCrap:{[index:string]:{[index:number]:boolean}};
|
||||
NestedPtr?:github_com_foomo_gotsrpc_demo_nested.Nested;
|
||||
NestedStruct:github_com_foomo_gotsrpc_demo_nested.Nested;
|
||||
}
|
||||
// github.com/foomo/gotsrpc/demo.Err
|
||||
export interface Err {
|
||||
message:string;
|
||||
}
|
||||
// github.com/foomo/gotsrpc/demo.Person
|
||||
export interface Person {
|
||||
Name:string;
|
||||
address?:github_com_foomo_gotsrpc_demo.Address;
|
||||
AddressStruct:github_com_foomo_gotsrpc_demo.Address;
|
||||
Addresses:{[index:string]:github_com_foomo_gotsrpc_demo.Address};
|
||||
InlinePtr?:{
|
||||
Foo:boolean;
|
||||
};
|
||||
InlineStruct:{
|
||||
Bar:string;
|
||||
};
|
||||
DNA:string;
|
||||
}
|
||||
// end of common js
|
||||
@ -48,6 +48,9 @@ module GoTSRPC.Demo {
|
||||
helloInterface(anything:any, anythingMap:{[index:string]:any}, anythingSlice:any[], success:() => void, err:(request:XMLHttpRequest, e?:Error) => void) {
|
||||
this.transport(this.endPoint, "HelloInterface", [anything, anythingMap, anythingSlice], success, err);
|
||||
}
|
||||
helloScalarError(success:(err:string) => void, err:(request:XMLHttpRequest, e?:Error) => void) {
|
||||
this.transport(this.endPoint, "HelloScalarError", [], success, err);
|
||||
}
|
||||
mapCrap(success:(crap:{[index:string]:number[]}) => void, err:(request:XMLHttpRequest, e?:Error) => void) {
|
||||
this.transport(this.endPoint, "MapCrap", [], success, err);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user