MCPcopy
hub / github.com/ContainerSSH/ContainerSSH / UnmarshalJSON

Method UnmarshalJSON

config/log.go:72–92  ·  view source on GitHub ↗

UnmarshalJSON decodes a JSON level string to a level type.

(data []byte)

Source from the content-addressed store, hash-verified

70
71// UnmarshalJSON decodes a JSON level string to a level type.
72func (level *LogLevel) UnmarshalJSON(data []byte) error {
73 var levelString LogLevelString
74 if err := json.Unmarshal(data, &levelString); err != nil {
75 unmarshalError := &json.UnmarshalTypeError{}
76 if errors.As(err, &unmarshalError) {
77 type levelAlias LogLevel
78 var l levelAlias
79 if err = json.Unmarshal(data, &l); err != nil {
80 return err
81 }
82 *level = LogLevel(l)
83 }
84 return err
85 }
86 l, err := levelString.ToLevel()
87 if err != nil {
88 return err
89 }
90 *level = l
91 return nil
92}
93
94// MarshalJSON marshals a level number to a JSON string
95func (level LogLevel) MarshalJSON() ([]byte, error) {

Callers

nothing calls this directly

Calls 3

ToLevelMethod · 0.95
LogLevelTypeAlias · 0.85
UnmarshalMethod · 0.80

Tested by

no test coverage detected