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
|
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() {
|
func main() {
|
||||||
cwd, err := os.Getwd()
|
cwd, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -99,8 +99,14 @@ func (p *GoApiParser) parseFile(sourceFile string) ([]api.Endpoint, error) {
|
|||||||
apiMethod.Name = funcDecl.Name.Name
|
apiMethod.Name = funcDecl.Name.Name
|
||||||
for _, param := range funcDecl.Type.Params.List {
|
for _, param := range funcDecl.Type.Params.List {
|
||||||
var apiPar api.Val
|
var apiPar api.Val
|
||||||
ident := param.Type.(*ast.Ident)
|
|
||||||
switch 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":
|
case "int":
|
||||||
apiPar.Type = api.TInt
|
apiPar.Type = api.TInt
|
||||||
case "string":
|
case "string":
|
||||||
@ -108,11 +114,20 @@ func (p *GoApiParser) parseFile(sourceFile string) ([]api.Endpoint, error) {
|
|||||||
case "bool":
|
case "bool":
|
||||||
apiPar.Type = api.TBool
|
apiPar.Type = api.TBool
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("parameter type %s is not supported yet", ident.Name)
|
return nil, fmt.Errorf("parameter type %s is not supported yet", paramType.Name)
|
||||||
}
|
}
|
||||||
if len(param.Names) != 1 {
|
case *ast.ArrayType:
|
||||||
return nil, fmt.Errorf("all parameters in method %s should be named", apiMethod.Name)
|
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
|
apiPar.Name = param.Names[0].Name
|
||||||
apiMethod.Params = append(apiMethod.Params, apiPar)
|
apiMethod.Params = append(apiMethod.Params, apiPar)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"efprojects.com/kitten-ipc/kitcom/internal/api"
|
"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/golang"
|
||||||
"efprojects.com/kitten-ipc/kitcom/internal/ts"
|
"efprojects.com/kitten-ipc/kitcom/internal/ts"
|
||||||
)
|
)
|
||||||
@ -114,9 +115,13 @@ func apiParserByPath(src string) (ApiParser, error) {
|
|||||||
func apiParserByFilePath(src string) (ApiParser, error) {
|
func apiParserByFilePath(src string) (ApiParser, error) {
|
||||||
switch path.Ext(src) {
|
switch path.Ext(src) {
|
||||||
case ".go":
|
case ".go":
|
||||||
return &golang.GoApiParser{}, nil
|
return &golang.GoApiParser{
|
||||||
|
Parser: &common.Parser{},
|
||||||
|
}, nil
|
||||||
case ".ts":
|
case ".ts":
|
||||||
return &ts.TypescriptApiParser{}, nil
|
return &ts.TypescriptApiParser{
|
||||||
|
Parser: &common.Parser{},
|
||||||
|
}, nil
|
||||||
case ".js":
|
case ".js":
|
||||||
return nil, fmt.Errorf("vanilla javascript is not supported and never will be")
|
return nil, fmt.Errorf("vanilla javascript is not supported and never will be")
|
||||||
case "":
|
case "":
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user