MCPcopy Create free account
hub / github.com/crossjoin-io/crossjoin / handle

Method handle

api/api.go:95–109  ·  view source on GitHub ↗
(method, route string, handler func(_ http.ResponseWriter, r *http.Request) Response)

Source from the content-addressed store, hash-verified

93}
94
95func (api *API) handle(method, route string, handler func(_ http.ResponseWriter, r *http.Request) Response) {
96 api.router.Methods(method).Path(route).HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
97 log.Println("handling", r.Method, r.URL.String())
98 resp := handler(w, r)
99 if resp.Error == "" {
100 resp.OK = true
101 }
102 if resp.Status > 0 {
103 w.WriteHeader(resp.Status)
104 }
105 w.Header().Add("content-type", "application/json")
106 enc := json.NewEncoder(w)
107 enc.Encode(resp)
108 })
109}

Callers 1

HandlerMethod · 0.95

Calls 1

StringMethod · 0.45

Tested by

no test coverage detected