main.go 1.6 KB

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