MCPcopy
hub / github.com/wavetermdev/waveterm / getWshMethodResponseType

Function getWshMethodResponseType

pkg/wshrpc/wshrpcmeta.go:39–66  ·  view source on GitHub ↗
(commandType string, method reflect.Method)

Source from the content-addressed store, hash-verified

37}
38
39func getWshMethodResponseType(commandType string, method reflect.Method) reflect.Type {
40 switch commandType {
41 case RpcType_ResponseStream:
42 if method.Type.NumOut() != 1 {
43 panic(fmt.Sprintf("method %q has invalid number of return values for response stream", method.Name))
44 }
45 outType := method.Type.Out(0)
46 if outType.Kind() != reflect.Chan {
47 panic(fmt.Sprintf("method %q has invalid return type %s for response stream", method.Name, outType))
48 }
49 elemType := outType.Elem()
50 if !strings.HasPrefix(elemType.Name(), "RespOrErrorUnion") {
51 panic(fmt.Sprintf("method %q has invalid return element type %s for response stream (should be RespOrErrorUnion)", method.Name, elemType))
52 }
53 respField, found := elemType.FieldByName("Response")
54 if !found {
55 panic(fmt.Sprintf("method %q has invalid return element type %s for response stream (missing Response field)", method.Name, elemType))
56 }
57 return respField.Type
58 case RpcType_Call:
59 if method.Type.NumOut() > 1 {
60 return method.Type.Out(0)
61 }
62 return nil
63 default:
64 panic(fmt.Sprintf("unsupported command type %q", commandType))
65 }
66}
67
68func generateWshCommandDecl(method reflect.Method) *WshRpcMethodDecl {
69 if method.Type.NumIn() == 0 || method.Type.In(0) != contextRType {

Callers 1

generateWshCommandDeclFunction · 0.85

Calls 1

NameMethod · 0.45

Tested by

no test coverage detected