diff --git a/example/golang/tsapi.gen.go b/example/golang/tsapi.gen.go index 78a00a7..9150f49 100644 --- a/example/golang/tsapi.gen.go +++ b/example/golang/tsapi.gen.go @@ -2,16 +2,27 @@ package main -import kittenipc "efprojects.com/kitten-ipc" +import ( + kittenipc "efprojects.com/kitten-ipc" + "fmt" +) + +type callable interface { + Call(method string, params ...any) (kittenipc.Vals, error) +} type TsIpcApi struct { - Ipc *kittenipc.KittenIPC + Ipc callable } func (t *TsIpcApi) Div( a int, b int, -) int { - return t.Ipc.Call( - "Div", a, b, - ) +) ( + int, error, +) { + results, err := t.Ipc.Call("TsIpcApi", "Div", a, b) + if err != nil { + return 0, fmt.Errorf("call to TsIpcApi.Div failed: %w", err) + } + return results[0].(int), nil } diff --git a/example/ts/src/goapi.gen.ts b/example/ts/src/goapi.gen.ts new file mode 100644 index 0000000..8b940f6 --- /dev/null +++ b/example/ts/src/goapi.gen.ts @@ -0,0 +1,14 @@ +import { ParentIPC, ChildIPC } from "kitten-ipc"; + +export default class IpcApi { + private ipc: ParentIPC | ChildIPC; + + constructor(ipc: ParentIPC | ChildIPC) { + this.ipc = ipc; + } + + async Div(a: number, b: number): Promise { + const results = await this.ipc.call("Div", a, b); + return results[0] as number; + } +} diff --git a/kitcom/go_gen.tmpl b/kitcom/go_gen.tmpl index 7bd77aa..9483b36 100644 --- a/kitcom/go_gen.tmpl +++ b/kitcom/go_gen.tmpl @@ -10,21 +10,25 @@ import ( kittenipc "efprojects.com/kitten-ipc" ) +type callable interface { + Call(method string, params ...any) (kittenipc.Vals, error) +} + {{range $e := .Api.Endpoints}} type {{.Name}} struct { - Ipc *kittenipc.KittenIPC + Ipc callable } {{range $mtd := $e.Methods}} func ({{$e.Name | receiver}} *{{$e.Name}}) {{$mtd.Name}}( {{range $mtd.Params}}{{.Name}} {{.Type | typedef}}, {{end}} ) ( -{{range $mtd.Ret}}{{.Type | typedef}}, {{end}}error +{{range $mtd.Ret}}{{.Type | typedef}}, {{end}}error, ) { results, err := {{$e.Name | receiver}}.Ipc.Call("{{$e.Name}}", "{{$mtd.Name}}"{{range $mtd.Params}}, {{.Name}}{{end}}) if err != nil { - return {{range $mtd.Ret}}{{.Type | zerovalue}}, {{end}}, fmt.Errorf("call to {{$e.Name}}.{{$mtd.Name}} failed: %w", err) + return {{range $mtd.Ret}}{{.Type | zerovalue}}, {{end}} fmt.Errorf("call to {{$e.Name}}.{{$mtd.Name}} failed: %w", err) } return {{range $idx, $ret := $mtd.Ret}}results[{{$idx}}].({{$ret.Type | typedef}}), {{end}}nil } diff --git a/lib/ts/src/index.ts b/lib/ts/src/index.ts new file mode 100644 index 0000000..35f7b93 --- /dev/null +++ b/lib/ts/src/index.ts @@ -0,0 +1 @@ +export {ParentIPC, ChildIPC} from './lib.js';