1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 10:08:15 -05:00
v2fly/main/confloader/confloader.go

35 lines
922 B
Go
Raw Normal View History

2019-12-15 20:33:41 -05:00
package confloader
import (
"io"
"os"
)
2020-01-02 20:26:48 -05:00
type configFileLoader func(string) (io.Reader, error)
type extconfigLoader func([]string, io.Reader) (io.Reader, error)
2019-12-15 20:33:41 -05:00
var (
EffectiveConfigFileLoader configFileLoader
2020-01-02 20:26:48 -05:00
EffectiveExtConfigLoader extconfigLoader
2019-12-15 20:33:41 -05:00
)
2020-01-02 20:26:48 -05:00
// LoadConfig reads from a path/url/stdin
// actual work is in external module
func LoadConfig(file string) (io.Reader, error) {
2019-12-15 20:33:41 -05:00
if EffectiveConfigFileLoader == nil {
2020-01-02 20:26:48 -05:00
newError("external config module not loaded, reading from stdin").AtInfo().WriteToLog()
2019-12-15 20:33:41 -05:00
return os.Stdin, nil
}
return EffectiveConfigFileLoader(file)
}
2020-01-02 20:26:48 -05: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-02 20:26:48 -05:00
if EffectiveExtConfigLoader == nil {
return nil, newError("external config module not loaded").AtError()
}
return EffectiveExtConfigLoader(files, reader)
2020-01-02 20:26:48 -05:00
}