confloader.go 922 B

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