some code
This commit is contained in:
parent
1b794147ec
commit
cafc5036ef
@ -21,6 +21,20 @@ func (api GoIpcApi) Div(a int, b int) (int, error) {
|
||||
return a / b, nil
|
||||
}
|
||||
|
||||
func (api GoIpcApi) XorData(data1 []byte, data2 []byte) ([]byte, error) {
|
||||
if len(data1) == 0 || len(data2) == 0 {
|
||||
return nil, fmt.Errorf("empty input data")
|
||||
}
|
||||
if len(data1) != len(data2) {
|
||||
return nil, fmt.Errorf("input data length mismatch")
|
||||
}
|
||||
result := make([]byte, len(data1))
|
||||
for i := 0; i < len(data1); i++ {
|
||||
result[i] = data1[i] ^ data2[i]
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
cwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
|
||||
@ -99,20 +99,35 @@ func (p *GoApiParser) parseFile(sourceFile string) ([]api.Endpoint, error) {
|
||||
apiMethod.Name = funcDecl.Name.Name
|
||||
for _, param := range funcDecl.Type.Params.List {
|
||||
var apiPar api.Val
|
||||
ident := param.Type.(*ast.Ident)
|
||||
switch ident.Name {
|
||||
case "int":
|
||||
apiPar.Type = api.TInt
|
||||
case "string":
|
||||
apiPar.Type = api.TString
|
||||
case "bool":
|
||||
apiPar.Type = api.TBool
|
||||
default:
|
||||
return nil, fmt.Errorf("parameter type %s is not supported yet", ident.Name)
|
||||
}
|
||||
|
||||
if len(param.Names) != 1 {
|
||||
return nil, fmt.Errorf("all parameters in method %s should be named", apiMethod.Name)
|
||||
}
|
||||
|
||||
switch paramType := param.Type.(type) {
|
||||
case *ast.Ident:
|
||||
switch paramType.Name {
|
||||
case "int":
|
||||
apiPar.Type = api.TInt
|
||||
case "string":
|
||||
apiPar.Type = api.TString
|
||||
case "bool":
|
||||
apiPar.Type = api.TBool
|
||||
default:
|
||||
return nil, fmt.Errorf("parameter type %s is not supported yet", paramType.Name)
|
||||
}
|
||||
case *ast.ArrayType:
|
||||
switch elementType := paramType.Elt.(type) {
|
||||
case *ast.Ident:
|
||||
switch elementType.Name {
|
||||
case "byte":
|
||||
apiPar.Type = api.TBlob
|
||||
default:
|
||||
return nil, fmt.Errorf("parameter type %s is not supported yet", paramType.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
apiPar.Name = param.Names[0].Name
|
||||
apiMethod.Params = append(apiMethod.Params, apiPar)
|
||||
}
|
||||
|
||||
@ -11,6 +11,7 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
"efprojects.com/kitten-ipc/kitcom/internal/api"
|
||||
"efprojects.com/kitten-ipc/kitcom/internal/common"
|
||||
"efprojects.com/kitten-ipc/kitcom/internal/golang"
|
||||
"efprojects.com/kitten-ipc/kitcom/internal/ts"
|
||||
)
|
||||
@ -114,9 +115,13 @@ func apiParserByPath(src string) (ApiParser, error) {
|
||||
func apiParserByFilePath(src string) (ApiParser, error) {
|
||||
switch path.Ext(src) {
|
||||
case ".go":
|
||||
return &golang.GoApiParser{}, nil
|
||||
return &golang.GoApiParser{
|
||||
Parser: &common.Parser{},
|
||||
}, nil
|
||||
case ".ts":
|
||||
return &ts.TypescriptApiParser{}, nil
|
||||
return &ts.TypescriptApiParser{
|
||||
Parser: &common.Parser{},
|
||||
}, nil
|
||||
case ".js":
|
||||
return nil, fmt.Errorf("vanilla javascript is not supported and never will be")
|
||||
case "":
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user