fixes
This commit is contained in:
parent
40bdc24422
commit
ba80965416
@ -9,7 +9,7 @@ import (
|
||||
"slices"
|
||||
"time"
|
||||
|
||||
kittenipc "github.com/egor3f/kitten-ipc"
|
||||
kittenipc "github.com/egor3f/kitten-ipc/lib/golang"
|
||||
)
|
||||
|
||||
// kittenipc:api
|
||||
|
||||
@ -5,7 +5,8 @@ package main
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
kittenipc "github.com/egor3f/kitten-ipc"
|
||||
|
||||
kittenipc "github.com/egor3f/kitten-ipc/lib/golang"
|
||||
)
|
||||
|
||||
var _ = base64.StdEncoding
|
||||
|
||||
@ -113,20 +113,22 @@ func (p *GoApiParser) parseFile(sourceFile string) ([]api.Endpoint, error) {
|
||||
|
||||
apiMethod.Params = append(apiMethod.Params, *apiPar)
|
||||
}
|
||||
for i, ret := range funcDecl.Type.Results.List {
|
||||
apiRet, err := fieldToVal(ret, true)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("parse return value %d for method %s: %w", i, apiMethod.Name, err)
|
||||
}
|
||||
if apiRet == nil {
|
||||
continue
|
||||
}
|
||||
if funcDecl.Type.Results != nil {
|
||||
for i, ret := range funcDecl.Type.Results.List {
|
||||
apiRet, err := fieldToVal(ret, true)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("parse return value %d for method %s: %w", i, apiMethod.Name, err)
|
||||
}
|
||||
if apiRet == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if len(ret.Names) > 0 {
|
||||
apiRet.Name = ret.Names[0].Name
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
||||
@ -129,9 +129,19 @@ func (ipc *ipcCommon) handleIncomingCall(msg Message) {
|
||||
args = append(args, reflect.ValueOf(arg))
|
||||
}
|
||||
|
||||
var errorType = reflect.TypeOf((*error)(nil)).Elem()
|
||||
|
||||
allResultVals := method.Call(args)
|
||||
retResultVals := allResultVals[0 : len(allResultVals)-1]
|
||||
errResultVals := allResultVals[len(allResultVals)-1]
|
||||
var retResultVals []reflect.Value
|
||||
var errResultVal reflect.Value
|
||||
if len(allResultVals) > 0 {
|
||||
if allResultVals[len(allResultVals)-1].Type().Implements(errorType) {
|
||||
retResultVals = allResultVals[0 : len(allResultVals)-1]
|
||||
errResultVal = allResultVals[len(allResultVals)-1]
|
||||
} else {
|
||||
retResultVals = allResultVals
|
||||
}
|
||||
}
|
||||
|
||||
var results []any
|
||||
for _, resVal := range retResultVals {
|
||||
@ -139,8 +149,8 @@ func (ipc *ipcCommon) handleIncomingCall(msg Message) {
|
||||
}
|
||||
|
||||
var resultError error
|
||||
if !errResultVals.IsNil() {
|
||||
resultError = errResultVals.Interface().(error)
|
||||
if errResultVal.IsValid() && !errResultVal.IsNil() {
|
||||
resultError = errResultVal.Interface().(error)
|
||||
}
|
||||
|
||||
ipc.sendResponse(msg.Id, results, resultError)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user