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

Method JSON

errors.go:55–74  ·  errors.go::Error.JSON

JSON creates a properly formatted JSON

()

Source from the content-addressed store, hash-verified

53
54// JSON creates a properly formatted JSON
55func (msg *Error) JSON() any {
56 jsonData := H{}
57 if msg.Meta != nil {
58 value := reflect.ValueOf(msg.Meta)
59 switch value.Kind() {
60 case reflect.Struct:
61 return msg.Meta
62 case reflect.Map:
63 for _, key := range value.MapKeys() {
64 jsonData[key.String()] = value.MapIndex(key).Interface()
65 }
66 default:
67 jsonData["meta"] = msg.Meta
68 }
69 }
70 if _, ok := jsonData["error"]; !ok {
71 jsonData["error"] = msg.Error()
72 }
73 return jsonData
74}
75
76// MarshalJSON implements the json.Marshaller interface.
77func (msg *Error) MarshalJSON() ([]byte, error) {

Callers 15

TestErrorFunction · 0.95
MarshalJSONMethod · 0.95
TestMiddlewareWriteFunction · 0.45
TestContextRenderJSONFunction · 0.45
TestContextRenderAPIJSONFunction · 0.45
githubConfigRouterFunction · 0.45
ErrorLoggerTFunction · 0.45
BenchmarkOneRouteJSONFunction · 0.45
TestLiteralColonWithRunFunction · 0.45

Calls 2

ErrorMethod · 0.95
StringMethod · 0.65

Tested by 13

TestErrorFunction · 0.76
TestMiddlewareWriteFunction · 0.36
TestContextRenderJSONFunction · 0.36
TestContextRenderAPIJSONFunction · 0.36
githubConfigRouterFunction · 0.36
BenchmarkOneRouteJSONFunction · 0.36
TestLiteralColonWithRunFunction · 0.36