(w http.ResponseWriter, r *http.Request)
| 105 | } |
| 106 | |
| 107 | func 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 | |
| 135 | func marshalReturnValue(data any, err error) []byte { |
| 136 | var mapRtn = make(map[string]any) |
nothing calls this directly
no test coverage detected