main.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "github.com/v2ray/v2ray-core"
  6. jsonconf "github.com/v2ray/v2ray-core/io/config/json"
  7. "github.com/v2ray/v2ray-core/log"
  8. // The following are neccesary as they register handlers in their init functions.
  9. _ "github.com/v2ray/v2ray-core/net/freedom"
  10. _ "github.com/v2ray/v2ray-core/net/socks"
  11. _ "github.com/v2ray/v2ray-core/net/vmess"
  12. )
  13. var (
  14. configFile = flag.String("config", "", "Config file for this Point server.")
  15. logLevel = flag.String("loglevel", "", "Level of log info to be printed to console, available value: debug, info, warning, error")
  16. version = flag.Bool("version", false, "Show current version of V2Ray.")
  17. )
  18. func main() {
  19. flag.Parse()
  20. if *version {
  21. fmt.Printf("V2Ray version %s (%s): %s", core.Version, core.Codename, core.Intro)
  22. fmt.Println()
  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. }
  35. if configFile == nil || len(*configFile) == 0 {
  36. panic(log.Error("Config file is not set."))
  37. }
  38. config, err := jsonconf.LoadConfig(*configFile)
  39. if err != nil {
  40. panic(log.Error("Failed to read config file (%s): %v", *configFile, err))
  41. }
  42. vPoint, err := core.NewPoint(config)
  43. if err != nil {
  44. panic(log.Error("Failed to create Point server: %v", err))
  45. }
  46. err = vPoint.Start()
  47. if err != nil {
  48. log.Error("Error starting Point server: %v", err)
  49. }
  50. finish := make(chan bool)
  51. <-finish
  52. }