Load loads rules files from disk.
(path string)
| 119 | |
| 120 | // Load loads rules files from disk. |
| 121 | func (l *Loader) Load(path string) error { |
| 122 | log.Debug("rules.Loader.Load(): %s", path) |
| 123 | if core.Exists(path) == false { |
| 124 | return fmt.Errorf("Path '%s' does not exist\nCreate it if you want to save rules to disk", path) |
| 125 | } |
| 126 | path, err := core.ExpandPath(path) |
| 127 | if err != nil { |
| 128 | return fmt.Errorf("Error accessing rules path: %s.\nCreate it if you want to save rules to disk", err) |
| 129 | } |
| 130 | |
| 131 | expr := filepath.Join(path, "*.json") |
| 132 | matches, err := filepath.Glob(expr) |
| 133 | if err != nil { |
| 134 | return fmt.Errorf("Error globbing '%s': %s", expr, err) |
| 135 | } |
| 136 | |
| 137 | l.Path = path |
| 138 | if len(l.rules) == 0 { |
| 139 | l.rules = make(map[string]*Rule) |
| 140 | } |
| 141 | |
| 142 | for _, fileName := range matches { |
| 143 | log.Debug("Reading rule from %s", fileName) |
| 144 | |
| 145 | if err := l.loadRule(fileName); err != nil { |
| 146 | log.Warning("%s", err) |
| 147 | continue |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | if l.liveReload && l.isLiveReloadRunning() == false { |
| 152 | go l.liveReloadWorker() |
| 153 | } |
| 154 | |
| 155 | return nil |
| 156 | } |
| 157 | |
| 158 | // Add adds a rule to the list of rules, and optionally saves it to disk. |
| 159 | func (l *Loader) Add(rule *Rule, saveToDisk bool) error { |