Save a rule to disk.
(rule *Rule, path string)
| 182 | |
| 183 | // Save a rule to disk. |
| 184 | func (l *Loader) Save(rule *Rule, path string) error { |
| 185 | // When saving the rule, use always RFC3339 format for the Created field (#1140). |
| 186 | rule.Updated = time.Now().Format(time.RFC3339) |
| 187 | raw, err := json.MarshalIndent(rule, "", " ") |
| 188 | if err != nil { |
| 189 | return fmt.Errorf("Error while saving rule %s to %s: %s", rule, path, err) |
| 190 | } |
| 191 | |
| 192 | if err = ioutil.WriteFile(path, raw, 0600); err != nil { |
| 193 | return fmt.Errorf("Error while saving rule %s to %s: %s", rule, path, err) |
| 194 | } |
| 195 | |
| 196 | return nil |
| 197 | } |
| 198 | |
| 199 | // Delete deletes a rule from the list by name. |
| 200 | // If the duration is Always (i.e: saved on disk), it'll attempt to delete |
no outgoing calls