UnmarshalJSON satisfies json.Unmarshaler.
(b []byte)
| 175 | |
| 176 | // UnmarshalJSON satisfies json.Unmarshaler. |
| 177 | func (sa *StringArray) UnmarshalJSON(b []byte) error { |
| 178 | var jsonObj any |
| 179 | err := json.Unmarshal(b, &jsonObj) |
| 180 | if err != nil { |
| 181 | return err |
| 182 | } |
| 183 | switch obj := jsonObj.(type) { |
| 184 | case string: |
| 185 | *sa = StringArray([]string{obj}) |
| 186 | return nil |
| 187 | case []any: |
| 188 | s := make([]string, 0, len(obj)) |
| 189 | for _, v := range obj { |
| 190 | value, ok := v.(string) |
| 191 | if !ok { |
| 192 | return errors.New("unsupported type") |
| 193 | } |
| 194 | s = append(s, value) |
| 195 | } |
| 196 | *sa = StringArray(s) |
| 197 | return nil |
| 198 | } |
| 199 | return errors.New("unsupported type") |
| 200 | } |
| 201 | |
| 202 | // errLogValues inspects err and returns the status code |
| 203 | // to use, the error log message, and any extra fields. |
nothing calls this directly
no test coverage detected