1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-05 09:47:56 -05:00
v2fly/main/confloader/confloader.go
2020-03-19 19:11:16 +08:00

35 lines
885 B
Go

package confloader
import (
"io"
"os"
)
type configFileLoader func(string) (io.Reader, error)
type extconfigLoader func([]string) (io.Reader, error)
var (
EffectiveConfigFileLoader configFileLoader
EffectiveExtConfigLoader extconfigLoader
)
// LoadConfig reads from a path/url/stdin
// actual work is in external module
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)
}
// LoadExtConfig calls v2ctl to handle multiple config
// the actual work also in external module
func LoadExtConfig(files []string) (io.Reader, error) {
if EffectiveExtConfigLoader == nil {
return nil, newError("external config module not loaded").AtError()
}
return EffectiveExtConfigLoader(files)
}