main.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "github.com/v2ray/v2ray-core"
  6. "github.com/v2ray/v2ray-core/common/log"
  7. jsonconf "github.com/v2ray/v2ray-core/config/json"
  8. // The following are neccesary as they register handlers in their init functions.
  9. _ "github.com/v2ray/v2ray-core/proxy/freedom"
  10. _ "github.com/v2ray/v2ray-core/proxy/freedom/config/json"
  11. _ "github.com/v2ray/v2ray-core/proxy/socks"
  12. _ "github.com/v2ray/v2ray-core/proxy/vmess"
  13. )
  14. var (
  15. configFile = flag.String("config", "", "Config file for this Point server.")
  16. logLevel = flag.String("loglevel", "warning", "Level of log info to be printed to console, available value: debug, info, warning, error")
  17. version = flag.Bool("version", false, "Show current version of V2Ray.")
  18. )
  19. func main() {
  20. flag.Parse()
  21. if *version {
  22. fmt.Printf("V2Ray %s (%s) %s", core.Version(), core.Codename, core.Build())
  23. fmt.Println()
  24. fmt.Println(core.Intro)
  25. return
  26. }
  27. switch *logLevel {
  28. case "debug":
  29. log.SetLogLevel(log.DebugLevel)
  30. case "info":
  31. log.SetLogLevel(log.InfoLevel)
  32. case "warning":
  33. log.SetLogLevel(log.WarningLevel)
  34. case "error":
  35. log.SetLogLevel(log.ErrorLevel)
  36. default:
  37. fmt.Println("Unknown log level: " + *logLevel)
  38. return
  39. }
  40. if configFile == nil || len(*configFile) == 0 {
  41. log.Error("Config file is not set.")
  42. return
  43. }
  44. config, err := jsonconf.LoadConfig(*configFile)
  45. if err != nil {
  46. log.Error("Failed to read config file (%s): %v", *configFile, err)
  47. return
  48. }
  49. if config.LogConfig() != nil && len(config.LogConfig().AccessLog()) > 0 {
  50. log.InitAccessLogger(config.LogConfig().AccessLog())
  51. }
  52. vPoint, err := core.NewPoint(config)
  53. if err != nil {
  54. log.Error("Failed to create Point server: %v", err)
  55. return
  56. }
  57. err = vPoint.Start()
  58. if err != nil {
  59. log.Error("Error starting Point server: %v", err)
  60. return
  61. }
  62. finish := make(chan bool)
  63. <-finish
  64. }