MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / handleService

Function handleService

pkg/web/web.go:107–133  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

105}
106
107func handleService(w http.ResponseWriter, r *http.Request) {
108 bodyData, err := io.ReadAll(r.Body)
109 if err != nil {
110 http.Error(w, "Unable to read request body", http.StatusBadRequest)
111 return
112 }
113 defer r.Body.Close()
114 if r.Method != http.MethodPost {
115 http.Error(w, "Invalid request method", http.StatusMethodNotAllowed)
116 return
117 }
118 var webCall service.WebCallType
119 err = json.Unmarshal(bodyData, &webCall)
120 if err != nil {
121 http.Error(w, fmt.Sprintf("invalid request body: %v", err), http.StatusBadRequest)
122 }
123
124 rtn := service.CallService(r.Context(), webCall)
125 jsonRtn, err := json.Marshal(rtn)
126 if err != nil {
127 http.Error(w, fmt.Sprintf("error serializing response: %v", err), http.StatusInternalServerError)
128 }
129 w.Header().Set(ContentTypeHeaderKey, ContentTypeJson)
130 w.Header().Set(ContentLengthHeaderKey, fmt.Sprintf("%d", len(jsonRtn)))
131 w.WriteHeader(http.StatusOK)
132 w.Write(jsonRtn)
133}
134
135func marshalReturnValue(data any, err error) []byte {
136 var mapRtn = make(map[string]any)

Callers

nothing calls this directly

Calls 9

CallServiceFunction · 0.92
CloseMethod · 0.65
WriteMethod · 0.65
ReadAllMethod · 0.45
ErrorMethod · 0.45
ContextMethod · 0.45
SetMethod · 0.45
HeaderMethod · 0.45
WriteHeaderMethod · 0.45

Tested by

no test coverage detected