Compare commits

..

No commits in common. "d50fb455478a8051b7838da2ed8065d17ec489b6" and "e7315c38aea8800f9f757fd274c94e71d92c6daa" have entirely different histories.

3 changed files with 13 additions and 33 deletions

View File

@ -12,9 +12,4 @@ export default class GoIpcApi {
const results = await this.ipc.call("GoIpcApi.Div", a, b);
return results[0] as number;
}
async XorData(data1: Uint8Array, data2: Uint8Array): Promise<Uint8Array> {
const results = await this.ipc.call("GoIpcApi.XorData", data1, data2);
return results[0] as Uint8Array;
}
}

View File

@ -97,13 +97,10 @@ func (p *GoApiParser) parseFile(sourceFile string) ([]api.Endpoint, error) {
if recvIdent.Name == endpoint.Name {
var apiMethod api.Method
apiMethod.Name = funcDecl.Name.Name
for i, param := range funcDecl.Type.Params.List {
apiPar, err := fieldToVal(param, false)
for _, param := range funcDecl.Type.Params.List {
apiPar, err := fieldToVal(param)
if err != nil {
return nil, fmt.Errorf("parse parameter %d for method %s: %w", i, apiMethod.Name, err)
}
if apiPar == nil {
continue
return nil, fmt.Errorf("parse parameter %s: %w", param.Names[0].Name, err)
}
if len(param.Names) != 1 {
@ -111,22 +108,19 @@ func (p *GoApiParser) parseFile(sourceFile string) ([]api.Endpoint, error) {
}
apiPar.Name = param.Names[0].Name
apiMethod.Params = append(apiMethod.Params, *apiPar)
apiMethod.Params = append(apiMethod.Params, apiPar)
}
for i, ret := range funcDecl.Type.Results.List {
apiRet, err := fieldToVal(ret, true)
for _, ret := range funcDecl.Type.Results.List {
apiRet, err := fieldToVal(ret)
if err != nil {
return nil, fmt.Errorf("parse return value %d for method %s: %w", i, apiMethod.Name, err)
}
if apiRet == nil {
continue
return nil, fmt.Errorf("parse return value %s: %w", ret.Names[0].Name, err)
}
if len(ret.Names) > 0 {
apiRet.Name = ret.Names[0].Name
}
apiMethod.Ret = append(apiMethod.Ret, *apiRet)
apiMethod.Ret = append(apiMethod.Ret, apiRet)
}
endpoints[i].Methods = append(endpoints[i].Methods, apiMethod)
}
@ -135,7 +129,7 @@ func (p *GoApiParser) parseFile(sourceFile string) ([]api.Endpoint, error) {
return endpoints, nil
}
func fieldToVal(param *ast.Field, returning bool) (*api.Val, error) {
func fieldToVal(param *ast.Field) (api.Val, error) {
var val api.Val
switch paramType := param.Type.(type) {
case *ast.Ident:
@ -146,14 +140,8 @@ func fieldToVal(param *ast.Field, returning bool) (*api.Val, error) {
val.Type = api.TString
case "bool":
val.Type = api.TBool
case "error":
if returning {
return nil, nil
} else {
return nil, fmt.Errorf("errors are supported only as return types")
}
default:
return nil, fmt.Errorf("parameter type %s is not supported yet", paramType.Name)
return val, fmt.Errorf("parameter type %s is not supported yet", paramType.Name)
}
case *ast.ArrayType:
switch elementType := paramType.Elt.(type) {
@ -162,13 +150,11 @@ func fieldToVal(param *ast.Field, returning bool) (*api.Val, error) {
case "byte":
val.Type = api.TBlob
default:
return nil, fmt.Errorf("parameter type %s is not supported yet", elementType.Name)
return val, fmt.Errorf("parameter type %s is not supported yet", elementType.Name)
}
default:
return nil, fmt.Errorf("parameter type %T is not supported yet", elementType)
}
default:
return nil, fmt.Errorf("parameter type %T is not supported yet", paramType)
return val, fmt.Errorf("parameter type %T is not supported yet", paramType)
}
return &val, nil
return val, nil
}

View File

@ -35,7 +35,6 @@ func (g *TypescriptApiGenerator) Generate(apis *api.Api, destFile string) error
api.TInt: "number",
api.TString: "string",
api.TBool: "boolean",
api.TBlob: "Uint8Array",
}[t]
if !ok {
return "", fmt.Errorf("cannot generate type %v", t)