MCPcopy
hub / github.com/perkeep/perkeep / discoveryHelper

Function discoveryHelper

pkg/server/root.go:279–294  ·  view source on GitHub ↗
(rw http.ResponseWriter, req *http.Request, dr *camtypes.Discovery)

Source from the content-addressed store, hash-verified

277}
278
279func discoveryHelper(rw http.ResponseWriter, req *http.Request, dr *camtypes.Discovery) {
280 rw.Header().Set("Content-Type", "text/javascript")
281 if cb := req.FormValue("cb"); identOrDotPattern.MatchString(cb) {
282 fmt.Fprintf(rw, "%s(", cb)
283 defer rw.Write([]byte(");\n"))
284 } else if v := req.FormValue("var"); identOrDotPattern.MatchString(v) {
285 fmt.Fprintf(rw, "%s = ", v)
286 defer rw.Write([]byte(";\n"))
287 }
288 bytes, err := json.MarshalIndent(dr, "", " ")
289 if err != nil {
290 httputil.ServeJSONError(rw, httputil.ServerError("encoding discovery information: "+err.Error()))
291 return
292 }
293 rw.Write(bytes)
294}

Callers 1

serveDiscoveryMethod · 0.85

Calls 5

ServeJSONErrorFunction · 0.92
ServerErrorTypeAlias · 0.92
SetMethod · 0.65
WriteMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected