main.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. core.PrintVersion()
  22. if *version {
  23. return
  24. }
  25. switch *logLevel {
  26. case "debug":
  27. log.SetLogLevel(log.DebugLevel)
  28. case "info":
  29. log.SetLogLevel(log.InfoLevel)
  30. case "warning":
  31. log.SetLogLevel(log.WarningLevel)
  32. case "error":
  33. log.SetLogLevel(log.ErrorLevel)
  34. default:
  35. fmt.Println("Unknown log level: " + *logLevel)
  36. return
  37. }
  38. if configFile == nil || len(*configFile) == 0 {
  39. log.Error("Config file is not set.")
  40. return
  41. }
  42. config, err := jsonconf.LoadConfig(*configFile)
  43. if err != nil {
  44. log.Error("Failed to read config file (%s): %v", *configFile, err)
  45. return
  46. }
  47. if config.LogConfig() != nil && len(config.LogConfig().AccessLog()) > 0 {
  48. log.InitAccessLogger(config.LogConfig().AccessLog())
  49. }
  50. vPoint, err := core.NewPoint(config)
  51. if err != nil {
  52. log.Error("Failed to create Point server: %v", err)
  53. return
  54. }
  55. err = vPoint.Start()
  56. if err != nil {
  57. log.Error("Error starting Point server: %v", err)
  58. return
  59. }
  60. finish := make(chan bool)
  61. <-finish
  62. }