MCPcopy Create free account
hub / github.com/CovenantSQL/CovenantSQL / resolveRPCEntities

Function resolveRPCEntities

cmd/cql/internal/rpc.go:326–372  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

324}
325
326func resolveRPCEntities() (req interface{}, resp interface{}) {
327 rpcParts := strings.SplitN(rpcName, ".", 2)
328
329 if len(rpcParts) != 2 {
330 // error rpc name
331 ConsoleLog.Errorf("%v is not a valid rpc name\n", rpcName)
332 SetExitStatus(1)
333 return
334 }
335
336 rpcService := rpcParts[0]
337
338 if s, supported := rpcServiceMap[rpcService]; supported {
339 typ := reflect.TypeOf(s)
340
341 // traversing methods
342 for m := 0; m < typ.NumMethod(); m++ {
343 method := typ.Method(m)
344 mtype := method.Type
345
346 if method.Name == rpcParts[1] {
347 // name matched
348 if mtype.PkgPath() != "" || mtype.NumIn() != 3 || mtype.NumOut() != 1 {
349 ConsoleLog.Infof("%v is not a valid rpc endpoint method\n", rpcName)
350 return
351 }
352
353 argType := mtype.In(1)
354 replyType := mtype.In(2)
355
356 if argType.Kind() == reflect.Ptr {
357 req = reflect.New(argType.Elem()).Interface()
358 } else {
359 req = reflect.New(argType).Interface()
360 }
361
362 resp = reflect.New(replyType.Elem()).Interface()
363
364 return
365 }
366 }
367 }
368
369 // not found
370 ConsoleLog.Infof("rpc method %v not found\n", rpcName)
371 return
372}

Callers 1

runRPCFunction · 0.85

Calls 4

SetExitStatusFunction · 0.85
ErrorfMethod · 0.80
InfofMethod · 0.80
NewMethod · 0.65

Tested by

no test coverage detected