MCPcopy Create free account
hub / github.com/goinaction/code / SendJSON

Function SendJSON

chapter9/listing17/handlers/handlers.go:15–27  ·  view source on GitHub ↗

SendJSON returns a simple JSON document.

(rw http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

13
14// SendJSON returns a simple JSON document.
15func SendJSON(rw http.ResponseWriter, r *http.Request) {
16 u := struct {
17 Name string
18 Email string
19 }{
20 Name: "Bill",
21 Email: "bill@ardanstudios.com",
22 }
23
24 rw.Header().Set("Content-Type", "application/json")
25 rw.WriteHeader(200)
26 json.NewEncoder(rw).Encode(&u)
27}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected