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)
|
2020-10-23 10:04:03 -04:00
|
|
|
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
|
2020-10-23 10:04:03 -04:00
|
|
|
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()
|
|
|
|
}
|
|
|
|
|
2020-10-23 10:04:03 -04:00
|
|
|
return EffectiveExtConfigLoader(files, reader)
|
2020-01-02 20:26:48 -05:00
|
|
|
}
|