Init initializes registered handlers.
(jsconfig json.RawMessage)
| 137 | |
| 138 | // Init initializes registered handlers. |
| 139 | func Init(jsconfig json.RawMessage) ([]string, error) { |
| 140 | var config []configType |
| 141 | |
| 142 | if err := json.Unmarshal(jsconfig, &config); err != nil { |
| 143 | return nil, errors.New("failed to parse config: " + err.Error()) |
| 144 | } |
| 145 | |
| 146 | var enabled []string |
| 147 | for _, cc := range config { |
| 148 | if hnd := handlers[cc.Name]; hnd != nil { |
| 149 | if ok, err := hnd.Init(cc.Config); err != nil { |
| 150 | return nil, err |
| 151 | } else if ok { |
| 152 | enabled = append(enabled, cc.Name) |
| 153 | } |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | return enabled, nil |
| 158 | } |
| 159 | |
| 160 | // Push a single message to devices. |
| 161 | func Push(msg *Receipt) { |