(filename string, updated chan struct{}, l *rate.Limiter)
| 1169 | } |
| 1170 | |
| 1171 | func WatchChanges(filename string, updated chan struct{}, l *rate.Limiter) { |
| 1172 | watcher, err := fsnotify.NewWatcher() |
| 1173 | capture(err) |
| 1174 | defer captureFunc(watcher.Close) |
| 1175 | done := make(chan bool) |
| 1176 | go func() { |
| 1177 | for { |
| 1178 | select { |
| 1179 | case event := <-watcher.Events: |
| 1180 | fmt.Println(event) |
| 1181 | if l != nil { |
| 1182 | if l.Allow() { |
| 1183 | updated <- struct{}{} |
| 1184 | } else { |
| 1185 | fmt.Println("skipping") |
| 1186 | } |
| 1187 | } |
| 1188 | case err := <-watcher.Errors: |
| 1189 | capture(err) |
| 1190 | } |
| 1191 | } |
| 1192 | }() |
| 1193 | if err := watcher.Add(filename); err != nil { |
| 1194 | capture(err) |
| 1195 | } |
| 1196 | <-done |
| 1197 | } |
| 1198 | |
| 1199 | func main() { |
| 1200 | cfg, err := loadConfig(configFile) |
no test coverage detected