2020-11-25 11:01:53 +00:00
|
|
|
package confloader
|
|
|
|
|
|
|
|
import (
|
2024-06-29 18:32:57 +00:00
|
|
|
"context"
|
2020-11-25 11:01:53 +00:00
|
|
|
"io"
|
|
|
|
"os"
|
2024-06-29 18:32:57 +00:00
|
|
|
|
|
|
|
"github.com/xtls/xray-core/common/errors"
|
2020-11-25 11:01:53 +00:00
|
|
|
)
|
|
|
|
|
2021-10-19 16:57:14 +00:00
|
|
|
type (
|
|
|
|
configFileLoader func(string) (io.Reader, error)
|
|
|
|
extconfigLoader func([]string, io.Reader) (io.Reader, error)
|
|
|
|
)
|
2020-11-25 11:01:53 +00:00
|
|
|
|
|
|
|
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 {
|
2024-06-29 18:32:57 +00:00
|
|
|
errors.LogInfo(context.Background(), "external config module not loaded, reading from stdin")
|
2020-11-25 11:01:53 +00:00
|
|
|
return os.Stdin, nil
|
|
|
|
}
|
|
|
|
return EffectiveConfigFileLoader(file)
|
|
|
|
}
|
|
|
|
|
|
|
|
// LoadExtConfig calls xctl to handle multiple config
|
|
|
|
// the actual work also in external module
|
|
|
|
func LoadExtConfig(files []string, reader io.Reader) (io.Reader, error) {
|
|
|
|
if EffectiveExtConfigLoader == nil {
|
2024-06-29 18:32:57 +00:00
|
|
|
return nil, errors.New("external config module not loaded").AtError()
|
2020-11-25 11:01:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return EffectiveExtConfigLoader(files, reader)
|
|
|
|
}
|