main.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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/socks"
  11. _ "github.com/v2ray/v2ray-core/proxy/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 %s (%s) %s", core.Version(), core.Codename, core.Build())
  22. fmt.Println()
  23. fmt.Println(core.Intro)
  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. }
  36. if configFile == nil || len(*configFile) == 0 {
  37. panic(log.Error("Config file is not set."))
  38. }
  39. config, err := jsonconf.LoadConfig(*configFile)
  40. if err != nil {
  41. panic(log.Error("Failed to read config file (%s): %v", *configFile, err))
  42. }
  43. vPoint, err := core.NewPoint(config)
  44. if err != nil {
  45. panic(log.Error("Failed to create Point server: %v", err))
  46. }
  47. err = vPoint.Start()
  48. if err != nil {
  49. log.Error("Error starting Point server: %v", err)
  50. }
  51. finish := make(chan bool)
  52. <-finish
  53. }