v2ray-core/release/server/main.go

76 lines
1.7 KiB
Go
Raw Normal View History

2015-09-12 09:51:42 +00:00
package main
2015-09-12 18:36:21 +00:00
import (
"flag"
2015-09-18 09:59:36 +00:00
"fmt"
2015-09-12 18:36:21 +00:00
"github.com/v2ray/v2ray-core"
2015-09-19 22:50:21 +00:00
"github.com/v2ray/v2ray-core/common/log"
jsonconf "github.com/v2ray/v2ray-core/config/json"
2015-09-12 18:36:21 +00:00
2015-09-13 18:01:50 +00:00
// The following are neccesary as they register handlers in their init functions.
2015-10-06 22:30:44 +00:00
_ "github.com/v2ray/v2ray-core/proxy/freedom"
2015-10-06 21:11:08 +00:00
_ "github.com/v2ray/v2ray-core/proxy/freedom/config/json"
_ "github.com/v2ray/v2ray-core/proxy/socks"
_ "github.com/v2ray/v2ray-core/proxy/vmess"
2015-09-12 18:36:21 +00:00
)
var (
2015-09-12 20:11:54 +00:00
configFile = flag.String("config", "", "Config file for this Point server.")
2015-10-07 08:05:11 +00:00
logLevel = flag.String("loglevel", "warning", "Level of log info to be printed to console, available value: debug, info, warning, error")
2015-09-18 09:59:36 +00:00
version = flag.Bool("version", false, "Show current version of V2Ray.")
2015-09-12 18:36:21 +00:00
)
2015-09-12 09:51:42 +00:00
func main() {
2015-09-12 18:36:21 +00:00
flag.Parse()
2015-09-15 22:06:22 +00:00
2015-10-13 12:30:37 +00:00
core.PrintVersion()
2015-09-18 09:59:36 +00:00
if *version {
return
}
2015-09-15 22:06:22 +00:00
switch *logLevel {
case "debug":
log.SetLogLevel(log.DebugLevel)
case "info":
log.SetLogLevel(log.InfoLevel)
case "warning":
log.SetLogLevel(log.WarningLevel)
case "error":
log.SetLogLevel(log.ErrorLevel)
2015-10-07 08:05:11 +00:00
default:
fmt.Println("Unknown log level: " + *logLevel)
return
2015-09-15 22:06:22 +00:00
}
2015-09-12 18:36:21 +00:00
if configFile == nil || len(*configFile) == 0 {
2015-10-07 08:05:11 +00:00
log.Error("Config file is not set.")
return
2015-09-12 18:36:21 +00:00
}
2015-09-19 13:35:20 +00:00
config, err := jsonconf.LoadConfig(*configFile)
2015-09-12 18:36:21 +00:00
if err != nil {
2015-10-07 08:05:11 +00:00
log.Error("Failed to read config file (%s): %v", *configFile, err)
return
2015-09-12 18:36:21 +00:00
}
2015-10-09 15:43:27 +00:00
if config.LogConfig() != nil && len(config.LogConfig().AccessLog()) > 0 {
log.InitAccessLogger(config.LogConfig().AccessLog())
}
vPoint, err := core.NewPoint(config)
2015-09-12 18:36:21 +00:00
if err != nil {
2015-10-07 08:05:11 +00:00
log.Error("Failed to create Point server: %v", err)
return
2015-09-12 18:36:21 +00:00
}
err = vPoint.Start()
if err != nil {
2015-09-12 20:11:54 +00:00
log.Error("Error starting Point server: %v", err)
2015-10-07 08:05:11 +00:00
return
2015-09-12 18:36:21 +00:00
}
2015-09-12 09:51:42 +00:00
2015-09-12 18:36:21 +00:00
finish := make(chan bool)
<-finish
2015-09-12 09:51:42 +00:00
}