MCPcopy Create free account
hub / github.com/BryanMwangi/pine / JSON

Method JSON

pine.go:619–632  ·  view source on GitHub ↗

JSON encodes data as JSON and writes it to the response.

(data interface{}, status ...int)

Source from the content-addressed store, hash-verified

617
618// JSON encodes data as JSON and writes it to the response.
619func (c *Ctx) JSON(data interface{}, status ...int) error {
620 raw, err := c.Server.config.JSONEncoder(data)
621 if err != nil {
622 return err
623 }
624 c.Response.Header().Set("Content-Type", "application/json")
625 if len(status) > 0 {
626 c.Response.WriteHeader(status[0])
627 } else {
628 c.Response.WriteHeader(http.StatusOK)
629 }
630 c.Response.Write(raw)
631 return nil
632}
633
634// Status sets the HTTP response status code.
635func (c *Ctx) Status(status int) *Ctx {

Callers 8

TestRequest_JSONFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
requireAPIKeyFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45

Calls 4

HeaderMethod · 0.80
WriteHeaderMethod · 0.80
SetMethod · 0.45
WriteMethod · 0.45

Tested by 1

TestRequest_JSONFunction · 0.36