1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-07-03 04:25:23 +00:00
v2fly/main/confloader/confloader.go

35 lines
922 B
Go
Raw Normal View History

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