mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-12-04 20:36:40 +00:00
079d0bd8a9
* Refactor log * Add new log methods * Fix logger test * Change all logging code * Clean up pathObj * Rebase to latest main * Remove invoking method name after the dot
40 lines
986 B
Go
40 lines
986 B
Go
package confloader
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"os"
|
|
|
|
"github.com/xtls/xray-core/common/errors"
|
|
)
|
|
|
|
type (
|
|
configFileLoader func(string) (io.Reader, error)
|
|
extconfigLoader func([]string, io.Reader) (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 {
|
|
errors.LogInfo(context.Background(), "external config module not loaded, reading from stdin")
|
|
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 {
|
|
return nil, errors.New("external config module not loaded").AtError()
|
|
}
|
|
|
|
return EffectiveExtConfigLoader(files, reader)
|
|
}
|