MCPcopy Create free account
hub / github.com/chain/Core / Write

Function Write

net/http/httpjson/io.go:39–47  ·  view source on GitHub ↗

Write sets the Content-Type header field to indicate JSON data, writes the header using status, then writes v to w. It logs any error encountered during the write.

(ctx context.Context, w http.ResponseWriter, status int, v interface{})

Source from the content-addressed store, hash-verified

37// then writes v to w.
38// It logs any error encountered during the write.
39func Write(ctx context.Context, w http.ResponseWriter, status int, v interface{}) {
40 w.Header().Set("Content-Type", "application/json; charset=utf-8")
41 w.WriteHeader(status)
42
43 err := json.NewEncoder(w).Encode(Array(v))
44 if err != nil {
45 log.Error(ctx, err)
46 }
47}
48
49// Array returns an empty JSON array if v is a nil slice,
50// so that it renders as "[]" rather than "null".

Callers 3

ServeHTTPMethod · 0.85
TestWriteArrayFunction · 0.85
TestWriteErrFunction · 0.85

Calls 6

ArrayFunction · 0.85
HeaderMethod · 0.80
WriteHeaderMethod · 0.80
EncodeMethod · 0.80
SetMethod · 0.45
ErrorMethod · 0.45

Tested by 2

TestWriteArrayFunction · 0.68
TestWriteErrFunction · 0.68