| 66 | } |
| 67 | |
| 68 | func 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 | |
| 91 | func MakeMethodMapForImpl(impl any, declMap map[string]*WshRpcMethodDecl) map[string]reflect.Method { |
| 92 | rtype := reflect.TypeOf(impl) |