UnmarshalJSON parses the JSON-encoded notification method configuration into MethodInfo.
(b []byte)
| 19 | |
| 20 | // UnmarshalJSON parses the JSON-encoded notification method configuration into MethodInfo. |
| 21 | func (c *MethodConfig) UnmarshalJSON(b []byte) error { |
| 22 | raw := struct { |
| 23 | Type Method `json:"type"` |
| 24 | Data json.RawMessage `json:"config"` |
| 25 | }{} |
| 26 | |
| 27 | if err := json.Unmarshal(b, &raw); err != nil { |
| 28 | return errors.Wrap(err, "error unmarshaling connection info JSON") |
| 29 | } |
| 30 | |
| 31 | c.Type = raw.Type |
| 32 | |
| 33 | if f := allSenders[raw.Type]; f == nil { |
| 34 | return errors.Errorf("sender type '%v' not registered", raw.Type) |
| 35 | } |
| 36 | |
| 37 | c.Config = defaultOptions[raw.Type] |
| 38 | if err := json.Unmarshal(raw.Data, &c.Config); err != nil { |
| 39 | return errors.Wrap(err, "unable to unmarshal config") |
| 40 | } |
| 41 | |
| 42 | return nil |
| 43 | } |
| 44 | |
| 45 | // Options unmarshals the configuration into the provided structure. |
| 46 | func (c MethodConfig) Options(result any) error { |