MCPcopy
hub / github.com/gophish/gophish / JSONResponse

Function JSONResponse

controllers/api/response.go:13–22  ·  view source on GitHub ↗

JSONResponse attempts to set the status code, c, and marshal the given interface, d, into a response that is written to the given ResponseWriter.

(w http.ResponseWriter, d interface{}, c int)

Source from the content-addressed store, hash-verified

11// JSONResponse attempts to set the status code, c, and marshal the given interface, d, into a response that
12// is written to the given ResponseWriter.
13func JSONResponse(w http.ResponseWriter, d interface{}, c int) {
14 dj, err := json.MarshalIndent(d, "", " ")
15 if err != nil {
16 http.Error(w, "Error creating JSON response", http.StatusInternalServerError)
17 log.Error(err)
18 }
19 w.Header().Set("Content-Type", "application/json")
20 w.WriteHeader(c)
21 fmt.Fprintf(w, "%s", dj)
22}

Callers 15

SettingsMethod · 0.92
TransparencyHandlerMethod · 0.92
PagesMethod · 0.85
PageMethod · 0.85
CampaignsMethod · 0.85
CampaignsSummaryMethod · 0.85
CampaignMethod · 0.85
CampaignResultsMethod · 0.85
CampaignSummaryMethod · 0.85
CampaignCompleteMethod · 0.85
ResetMethod · 0.85
GroupsMethod · 0.85

Calls 1

ErrorMethod · 0.65

Tested by

no test coverage detected