confloader.go 923 B

123456789101112131415161718192021222324252627282930313233343536
  1. package confloader
  2. import (
  3. "io"
  4. "os"
  5. )
  6. type (
  7. configFileLoader func(string) (io.Reader, error)
  8. extconfigLoader func([]string, io.Reader) (io.Reader, error)
  9. )
  10. var (
  11. EffectiveConfigFileLoader configFileLoader
  12. EffectiveExtConfigLoader extconfigLoader
  13. )
  14. // LoadConfig reads from a path/url/stdin
  15. // actual work is in external module
  16. func LoadConfig(file string) (io.Reader, error) {
  17. if EffectiveConfigFileLoader == nil {
  18. newError("external config module not loaded, reading from stdin").AtInfo().WriteToLog()
  19. return os.Stdin, nil
  20. }
  21. return EffectiveConfigFileLoader(file)
  22. }
  23. // LoadExtConfig calls xctl to handle multiple config
  24. // the actual work also in external module
  25. func LoadExtConfig(files []string, reader io.Reader) (io.Reader, error) {
  26. if EffectiveExtConfigLoader == nil {
  27. return nil, newError("external config module not loaded").AtError()
  28. }
  29. return EffectiveExtConfigLoader(files, reader)
  30. }