MCPcopy
hub / github.com/kopia/kopia / UnmarshalJSON

Method UnmarshalJSON

notification/sender/sender_config.go:21–43  ·  view source on GitHub ↗

UnmarshalJSON parses the JSON-encoded notification method configuration into MethodInfo.

(b []byte)

Source from the content-addressed store, hash-verified

19
20// UnmarshalJSON parses the JSON-encoded notification method configuration into MethodInfo.
21func (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.
46func (c MethodConfig) Options(result any) error {

Callers

nothing calls this directly

Calls 1

ErrorfMethod · 0.80

Tested by

no test coverage detected