mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-21 17:46:58 -05:00
add env variable for config file
This commit is contained in:
parent
81c4f23691
commit
53b0f91873
@ -70,3 +70,9 @@ func GetPluginDirectory() string {
|
|||||||
pluginDir := EnvFlag{Name: name, AltName: NormalizeEnvName(name)}.GetValue(getExecuableSubDir("plugins"))
|
pluginDir := EnvFlag{Name: name, AltName: NormalizeEnvName(name)}.GetValue(getExecuableSubDir("plugins"))
|
||||||
return pluginDir
|
return pluginDir
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetConfigurationPath() string {
|
||||||
|
const name = "v2ray.location.config"
|
||||||
|
configPath := EnvFlag{Name: name, AltName: NormalizeEnvName(name)}.GetValue(getExecutableDir)
|
||||||
|
return filepath.Join(configPath, "config.json")
|
||||||
|
}
|
||||||
|
35
main/main.go
35
main/main.go
@ -13,25 +13,40 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"v2ray.com/core"
|
"v2ray.com/core"
|
||||||
|
"v2ray.com/core/common/platform"
|
||||||
_ "v2ray.com/core/main/distro/all"
|
_ "v2ray.com/core/main/distro/all"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
configFile string
|
configFile = flag.String("config", "", "Config file for V2Ray.")
|
||||||
version = flag.Bool("version", false, "Show current version of V2Ray.")
|
version = flag.Bool("version", false, "Show current version of V2Ray.")
|
||||||
test = flag.Bool("test", false, "Test config file only, without launching V2Ray server.")
|
test = flag.Bool("test", false, "Test config file only, without launching V2Ray server.")
|
||||||
format = flag.String("format", "json", "Format of input file.")
|
format = flag.String("format", "json", "Format of input file.")
|
||||||
plugin = flag.Bool("plugin", false, "True to load plugins.")
|
plugin = flag.Bool("plugin", false, "True to load plugins.")
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func fileExists(file string) bool {
|
||||||
defaultConfigFile := ""
|
info, err := os.Stat(file)
|
||||||
workingDir, err := filepath.Abs(filepath.Dir(os.Args[0]))
|
return err == nil && !info.IsDir()
|
||||||
if err == nil {
|
}
|
||||||
defaultConfigFile = filepath.Join(workingDir, "config.json")
|
|
||||||
|
func getConfigFilePath() string {
|
||||||
|
if len(*configFile) > 0 {
|
||||||
|
return *configFile
|
||||||
}
|
}
|
||||||
flag.StringVar(&configFile, "config", defaultConfigFile, "Config file for this Point server.")
|
|
||||||
|
if workingDir, err := os.Getwd(); err == nil {
|
||||||
|
configFile := filepath.Join(workingDir, "config.json")
|
||||||
|
if fileExists(configFile) {
|
||||||
|
return configFile
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if configFile := platform.GetConfigurationPath(); fileExists(configFile) {
|
||||||
|
return configFile
|
||||||
|
}
|
||||||
|
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetConfigFormat() core.ConfigFormat {
|
func GetConfigFormat() core.ConfigFormat {
|
||||||
@ -46,9 +61,7 @@ func GetConfigFormat() core.ConfigFormat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func startV2Ray() (core.Server, error) {
|
func startV2Ray() (core.Server, error) {
|
||||||
if len(configFile) == 0 {
|
configFile := getConfigFilePath()
|
||||||
return nil, newError("config file is not set")
|
|
||||||
}
|
|
||||||
var configInput io.Reader
|
var configInput io.Reader
|
||||||
if configFile == "stdin:" {
|
if configFile == "stdin:" {
|
||||||
configInput = os.Stdin
|
configInput = os.Stdin
|
||||||
|
Loading…
Reference in New Issue
Block a user