MCPcopy Create free account
hub / github.com/wavetermdev/waveterm / generateWshCommandDecl

Function generateWshCommandDecl

pkg/wshrpc/wshrpcmeta.go:68–89  ·  view source on GitHub ↗
(method reflect.Method)

Source from the content-addressed store, hash-verified

66}
67
68func generateWshCommandDecl(method reflect.Method) *WshRpcMethodDecl {
69 if method.Type.NumIn() == 0 || method.Type.In(0) != contextRType {
70 panic(fmt.Sprintf("method %q does not have context as first argument", method.Name))
71 }
72 cmdStr := method.Name
73 decl := &WshRpcMethodDecl{}
74 // remove Command suffix
75 if !strings.HasSuffix(cmdStr, "Command") {
76 panic(fmt.Sprintf("method %q does not have Command suffix", cmdStr))
77 }
78 cmdStr = cmdStr[:len(cmdStr)-len("Command")]
79 decl.Command = strings.ToLower(cmdStr)
80 decl.CommandType = getWshCommandType(method)
81 decl.MethodName = method.Name
82 var cdataTypes []reflect.Type
83 for idx := 1; idx < method.Type.NumIn(); idx++ {
84 cdataTypes = append(cdataTypes, method.Type.In(idx))
85 }
86 decl.CommandDataTypes = cdataTypes
87 decl.DefaultResponseDataType = getWshMethodResponseType(decl.CommandType, method)
88 return decl
89}
90
91func MakeMethodMapForImpl(impl any, declMap map[string]*WshRpcMethodDecl) map[string]reflect.Method {
92 rtype := reflect.TypeOf(impl)

Callers 2

Calls 2

getWshCommandTypeFunction · 0.85
getWshMethodResponseTypeFunction · 0.85

Tested by 1