mirror of https://github.com/v2ray/v2ray-core
Smart config file
parent
b6a0d0aba9
commit
9803bfc3a9
|
@ -3,6 +3,8 @@ package main
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/v2ray/v2ray-core"
|
"github.com/v2ray/v2ray-core"
|
||||||
"github.com/v2ray/v2ray-core/app/point"
|
"github.com/v2ray/v2ray-core/app/point"
|
||||||
|
@ -18,11 +20,20 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
configFile = flag.String("config", "config.json", "Config file for this Point server.")
|
configFile string
|
||||||
logLevel = flag.String("loglevel", "warning", "Level of log info to be printed to console, available value: debug, info, warning, error")
|
logLevel = flag.String("loglevel", "warning", "Level of log info to be printed to console, available value: debug, info, warning, error")
|
||||||
version = flag.Bool("version", false, "Show current version of V2Ray.")
|
version = flag.Bool("version", false, "Show current version of V2Ray.")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
defaultConfigFile := ""
|
||||||
|
workingDir, err := filepath.Abs(filepath.Dir(os.Args[0]))
|
||||||
|
if err == nil {
|
||||||
|
defaultConfigFile = filepath.Join(workingDir, "config.json")
|
||||||
|
}
|
||||||
|
flag.StringVar(&configFile, "config", defaultConfigFile, "Config file for this Point server.")
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
@ -46,13 +57,13 @@ func main() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if configFile == nil || len(*configFile) == 0 {
|
if len(configFile) == 0 {
|
||||||
log.Error("Config file is not set.")
|
log.Error("Config file is not set.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
config, err := jsonconf.LoadConfig(*configFile)
|
config, err := jsonconf.LoadConfig(configFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Failed to read config file (%s): %v", *configFile, err)
|
log.Error("Failed to read config file (%s): %v", configFile, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
|
|
||||||
func buildV2Ray(targetFile string, version string, goOS GoOS, goArch GoArch) error {
|
func buildV2Ray(targetFile string, version string, goOS GoOS, goArch GoArch) error {
|
||||||
ldFlags := "-s"
|
ldFlags := "-s"
|
||||||
if version != "" {
|
if version != "custom" {
|
||||||
year, month, day := time.Now().UTC().Date()
|
year, month, day := time.Now().UTC().Date()
|
||||||
today := fmt.Sprintf("%04d%02d%02d", year, int(month), day)
|
today := fmt.Sprintf("%04d%02d%02d", year, int(month), day)
|
||||||
ldFlags = ldFlags + " -X github.com/v2ray/v2ray-core.version=" + version + " -X github.com/v2ray/v2ray-core.build=" + today
|
ldFlags = ldFlags + " -X github.com/v2ray/v2ray-core.version=" + version + " -X github.com/v2ray/v2ray-core.build=" + today
|
||||||
|
@ -17,6 +17,9 @@ func buildV2Ray(targetFile string, version string, goOS GoOS, goArch GoArch) err
|
||||||
cmd := exec.Command("go", "build", "-o", targetFile, "-compiler", "gc", "-ldflags", ldFlags, "github.com/v2ray/v2ray-core/release/server")
|
cmd := exec.Command("go", "build", "-o", targetFile, "-compiler", "gc", "-ldflags", ldFlags, "github.com/v2ray/v2ray-core/release/server")
|
||||||
cmd.Env = append(cmd.Env, "GOOS="+string(goOS), "GOARCH="+string(goArch))
|
cmd.Env = append(cmd.Env, "GOOS="+string(goOS), "GOARCH="+string(goArch))
|
||||||
cmd.Env = append(cmd.Env, os.Environ()...)
|
cmd.Env = append(cmd.Env, os.Environ()...)
|
||||||
_, err := cmd.Output()
|
output, err := cmd.CombinedOutput()
|
||||||
|
if len(output) > 0 {
|
||||||
|
fmt.Println(string(output))
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue