| 263 | type scanCallback func(path string) |
| 264 | |
| 265 | func scanChanges(watchPath string, excludeDirs []string, allFiles bool, cb scanCallback) { |
| 266 | for { |
| 267 | filepath.Walk(watchPath, func(path string, info os.FileInfo, err error) error { |
| 268 | if path == ".git" && info.IsDir() { |
| 269 | return filepath.SkipDir |
| 270 | } |
| 271 | for _, x := range excludeDirs { |
| 272 | if x == path { |
| 273 | return filepath.SkipDir |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | // ignore hidden files |
| 278 | if filepath.Base(path)[0] == '.' { |
| 279 | return nil |
| 280 | } |
| 281 | |
| 282 | if (allFiles || filepath.Ext(path) == ".go") && info.ModTime().After(startTime) { |
| 283 | cb(path) |
| 284 | startTime = time.Now() |
| 285 | return errors.New("done") |
| 286 | } |
| 287 | |
| 288 | return nil |
| 289 | }) |
| 290 | time.Sleep(500 * time.Millisecond) |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | func shutdown(runner gin.Runner) { |
| 295 | c := make(chan os.Signal, 2) |