v2ray-core/main/confloader/confloader.go

35 lines
885 B
Go
Raw Normal View History

2019-12-16 09:33:41 +08:00
package confloader
import (
"io"
"os"
)
type configFileLoader func(string) (io.Reader, error)
type extconfigLoader func([]string) (io.Reader, error)
var (
EffectiveConfigFileLoader configFileLoader
EffectiveExtConfigLoader extconfigLoader
)
2019-12-24 01:13:10 +08:00
// LoadConfig reads from a path/url/stdin
// actual work is in external module
2019-12-16 09:33:41 +08:00
func LoadConfig(file string) (io.Reader, error) {
if EffectiveConfigFileLoader == nil {
newError("external config module not loaded, reading from stdin").AtInfo().WriteToLog()
return os.Stdin, nil
}
return EffectiveConfigFileLoader(file)
}
2019-12-24 01:13:10 +08:00
// LoadExtConfig calls v2ctl to handle multiple config
// the actual work also in external module
2019-12-16 09:33:41 +08:00
func LoadExtConfig(files []string) (io.Reader, error) {
if EffectiveExtConfigLoader == nil {
return nil, newError("external config module not loaded").AtError()
}
return EffectiveExtConfigLoader(files)
}