MCPcopy
hub / github.com/gin-gonic/gin / Render

Method Render

render/json.go:94–109  ·  view source on GitHub ↗

Render (SecureJSON) marshals the given interface object and writes it with custom ContentType.

(w http.ResponseWriter)

Source from the content-addressed store, hash-verified

92
93// Render (SecureJSON) marshals the given interface object and writes it with custom ContentType.
94func (r SecureJSON) Render(w http.ResponseWriter) error {
95 r.WriteContentType(w)
96 jsonBytes, err := json.API.Marshal(r.Data)
97 if err != nil {
98 return err
99 }
100 // if the jsonBytes is array values
101 if bytes.HasPrefix(jsonBytes, bytesconv.StringToBytes("[")) && bytes.HasSuffix(jsonBytes,
102 bytesconv.StringToBytes("]")) {
103 if _, err = w.Write(bytesconv.StringToBytes(r.Prefix)); err != nil {
104 return err
105 }
106 }
107 _, err = w.Write(jsonBytes)
108 return err
109}
110
111// WriteContentType (SecureJSON) writes JSON ContentType.
112func (r SecureJSON) WriteContentType(w http.ResponseWriter) {

Callers 1

TestRenderWriteErrorFunction · 0.95

Calls 4

WriteContentTypeMethod · 0.95
StringToBytesFunction · 0.92
MarshalMethod · 0.65
WriteMethod · 0.45

Tested by 1

TestRenderWriteErrorFunction · 0.76