loaded_sources.go 888 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package config
  2. import "sync"
  3. var (
  4. loadedSourcesMu sync.Mutex
  5. loadedSources []string
  6. )
  7. // BeginLoadedSources clears the list of config files recorded for the current load.
  8. func BeginLoadedSources() {
  9. loadedSourcesMu.Lock()
  10. defer loadedSourcesMu.Unlock()
  11. loadedSources = nil
  12. }
  13. // RecordLoadedSource records a config file that was successfully read during parsing.
  14. func RecordLoadedSource(path string) {
  15. if path == "" {
  16. return
  17. }
  18. loadedSourcesMu.Lock()
  19. defer loadedSourcesMu.Unlock()
  20. for _, existing := range loadedSources {
  21. if existing == path {
  22. return
  23. }
  24. }
  25. loadedSources = append(loadedSources, path)
  26. }
  27. // LoadedSources returns a copy of config files read during the latest config load.
  28. func LoadedSources() []string {
  29. loadedSourcesMu.Lock()
  30. defer loadedSourcesMu.Unlock()
  31. out := make([]string, len(loadedSources))
  32. copy(out, loadedSources)
  33. return out
  34. }