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

Function ExampleSendJSON

chapter9/listing17/handlers/handlers_example_test.go:13–30  ·  view source on GitHub ↗

ExampleSendJSON provides a basic example.

()

Source from the content-addressed store, hash-verified

11
12// ExampleSendJSON provides a basic example.
13func ExampleSendJSON() {
14 r, _ := http.NewRequest("GET", "/sendjson", nil)
15 w := httptest.NewRecorder()
16 http.DefaultServeMux.ServeHTTP(w, r)
17
18 var u struct {
19 Name string
20 Email string
21 }
22
23 if err := json.NewDecoder(w.Body).Decode(&u); err != nil {
24 log.Println("ERROR:", err)
25 }
26
27 fmt.Println(u)
28 // Output:
29 // {Bill bill@ardanstudios.com}
30}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected