MCPcopy Create free account
hub / github.com/coder/slog / encodeStruct

Function encodeStruct

map.go:122–134  ·  view source on GitHub ↗
(rv reflect.Value)

Source from the content-addressed store, hash-verified

120}
121
122func encodeStruct(rv reflect.Value) ([]byte, bool) {
123 if rv.Kind() == reflect.Struct {
124 for i := 0; i < rv.NumField(); i++ {
125 ft := rv.Type().Field(i)
126 // Found a field with a json tag.
127 if ft.Tag.Get("json") != "" {
128 return encodeJSON(rv.Interface()), true
129 }
130 }
131 }
132
133 return nil, false
134}
135
136func encodeJSON(v interface{}) []byte {
137 b, err := json.Marshal(v)

Callers 1

encodeFunction · 0.85

Calls 1

encodeJSONFunction · 0.85

Tested by

no test coverage detected