support for []byte (code not finished, temp commit)
This commit is contained in:
parent
6b7014a2b7
commit
f24a0d706c
@ -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)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user