Download internal/objects/json.go from llzai/axonhub: direct link, hf CLI and curl.
- Browser
- Download file 1.2 kB
-
https://huggingface.co/spaces/llzai/axonhub/resolve/main/internal/objects/json.go
- Command line
-
hf download hf://spaces/llzai/axonhub/internal/objects/json.go
-
curl -L -o json.go https://huggingface.co/spaces/llzai/axonhub/resolve/main/internal/objects/json.go
1.2 kB
| package objects | |
| import ( | |
| "encoding/json" | |
| "errors" | |
| "io" | |
| ) | |
| type JSONRawMessage []byte | |
| // MarshalJSON returns m as the JSON encoding of m. | |
| func (m JSONRawMessage) MarshalJSON() ([]byte, error) { | |
| if m == nil { | |
| return []byte("null"), nil | |
| } | |
| return m, nil | |
| } | |
| // UnmarshalJSON sets *m to a copy of data. | |
| func (m *JSONRawMessage) UnmarshalJSON(data []byte) error { | |
| if m == nil { | |
| return errors.New("json.RawMessage: UnmarshalJSON on nil pointer") | |
| } | |
| *m = append((*m)[0:0], data...) | |
| return nil | |
| } | |
| // MarshalGQL returns m as the JSON encoding of m. | |
| func (m JSONRawMessage) MarshalGQL(w io.Writer) { | |
| if m == nil { | |
| _, _ = w.Write([]byte("null")) | |
| return | |
| } | |
| _, _ = w.Write(m) | |
| } | |
| // UnmarshalGQL sets *m to a copy of data. | |
| func (m *JSONRawMessage) UnmarshalGQL(v any) error { | |
| if m == nil { | |
| return errors.New("json.RawMessage: UnmarshalGQL on nil pointer") | |
| } | |
| switch v := v.(type) { | |
| case *JSONRawMessage: | |
| *m = append((*m)[0:0], *v...) | |
| return nil | |
| case *string: | |
| *v = string(*m) | |
| return nil | |
| case *[]byte: | |
| *v = append((*v)[0:0], *m...) | |
| return nil | |
| case *map[string]any: | |
| return json.Unmarshal(*m, v) | |
| } | |
| return nil | |
| } | |