loaded_sources.go 877 B

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