| 74 | } |
| 75 | |
| 76 | func GenMethod_Call(buf *strings.Builder, methodDecl *wshrpc.WshRpcMethodDecl) { |
| 77 | fmt.Fprintf(buf, "// command %q, wshserver.%s\n", methodDecl.Command, methodDecl.MethodName) |
| 78 | dataType, dataVarName := getWshMethodDataParamsAndExpr(methodDecl) |
| 79 | returnType := "error" |
| 80 | respName := "_" |
| 81 | tParamVal := "any" |
| 82 | if methodDecl.DefaultResponseDataType != nil { |
| 83 | returnType = "(" + methodDecl.DefaultResponseDataType.String() + ", error)" |
| 84 | respName = "resp" |
| 85 | tParamVal = methodDecl.DefaultResponseDataType.String() |
| 86 | } |
| 87 | fmt.Fprintf(buf, "func %s(w *wshutil.WshRpc%s, opts *wshrpc.RpcOpts) %s {\n", methodDecl.MethodName, dataType, returnType) |
| 88 | fmt.Fprintf(buf, "\t%s, err := sendRpcRequestCallHelper[%s](w, %q, %s, opts)\n", respName, tParamVal, methodDecl.Command, dataVarName) |
| 89 | if methodDecl.DefaultResponseDataType != nil { |
| 90 | fmt.Fprintf(buf, "\treturn resp, err\n") |
| 91 | } else { |
| 92 | fmt.Fprintf(buf, "\treturn err\n") |
| 93 | } |
| 94 | fmt.Fprintf(buf, "}\n\n") |
| 95 | } |
| 96 | |
| 97 | func GenMethod_ResponseStream(buf *strings.Builder, methodDecl *wshrpc.WshRpcMethodDecl) { |
| 98 | fmt.Fprintf(buf, "// command %q, wshserver.%s\n", methodDecl.Command, methodDecl.MethodName) |