confloader.go 544 B

123456789101112131415161718192021222324252627
  1. package confloader
  2. import (
  3. "context"
  4. "io"
  5. "os"
  6. "github.com/xtls/xray-core/common/errors"
  7. )
  8. type (
  9. configFileLoader func(string) (io.Reader, error)
  10. )
  11. var (
  12. EffectiveConfigFileLoader configFileLoader
  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. errors.LogInfo(context.Background(), "external config module not loaded, reading from stdin")
  19. return os.Stdin, nil
  20. }
  21. return EffectiveConfigFileLoader(file)
  22. }