tons of code

This commit is contained in:
Egor Aristov 2025-10-25 13:09:27 +03:00
parent 6051aaba16
commit 3ebfa08350
Signed by: egor3f
GPG Key ID: 40482A264AAEC85F
4 changed files with 39 additions and 9 deletions

View File

@ -2,16 +2,27 @@
package main 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 { type TsIpcApi struct {
Ipc *kittenipc.KittenIPC Ipc callable
} }
func (t *TsIpcApi) Div( func (t *TsIpcApi) Div(
a int, b int, a int, b int,
) int { ) (
return t.Ipc.Call( int, error,
"Div", a, b, ) {
) 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
} }

View File

@ -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<number> {
const results = await this.ipc.call("Div", a, b);
return results[0] as number;
}
}

View File

@ -10,21 +10,25 @@ import (
kittenipc "efprojects.com/kitten-ipc" kittenipc "efprojects.com/kitten-ipc"
) )
type callable interface {
Call(method string, params ...any) (kittenipc.Vals, error)
}
{{range $e := .Api.Endpoints}} {{range $e := .Api.Endpoints}}
type {{.Name}} struct { type {{.Name}} struct {
Ipc *kittenipc.KittenIPC Ipc callable
} }
{{range $mtd := $e.Methods}} {{range $mtd := $e.Methods}}
func ({{$e.Name | receiver}} *{{$e.Name}}) {{$mtd.Name}}( func ({{$e.Name | receiver}} *{{$e.Name}}) {{$mtd.Name}}(
{{range $mtd.Params}}{{.Name}} {{.Type | typedef}}, {{end}} {{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}}) results, err := {{$e.Name | receiver}}.Ipc.Call("{{$e.Name}}", "{{$mtd.Name}}"{{range $mtd.Params}}, {{.Name}}{{end}})
if err != nil { 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 return {{range $idx, $ret := $mtd.Ret}}results[{{$idx}}].({{$ret.Type | typedef}}), {{end}}nil
} }

1
lib/ts/src/index.ts Normal file
View File

@ -0,0 +1 @@
export {ParentIPC, ChildIPC} from './lib.js';