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