main.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package main
  2. import (
  3. "flag"
  4. "io/ioutil"
  5. "path"
  6. "github.com/v2ray/v2ray-core"
  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. )
  17. func main() {
  18. flag.Parse()
  19. switch *logLevel {
  20. case "debug":
  21. log.SetLogLevel(log.DebugLevel)
  22. case "info":
  23. log.SetLogLevel(log.InfoLevel)
  24. case "warning":
  25. log.SetLogLevel(log.WarningLevel)
  26. case "error":
  27. log.SetLogLevel(log.ErrorLevel)
  28. }
  29. if configFile == nil || len(*configFile) == 0 {
  30. panic(log.Error("Config file is not set."))
  31. }
  32. rawVConfig, err := ioutil.ReadFile(*configFile)
  33. if err != nil {
  34. panic(log.Error("Failed to read config file (%s): %v", *configFile, err))
  35. }
  36. vconfig, err := core.LoadConfig(rawVConfig)
  37. if err != nil {
  38. panic(log.Error("Failed to parse Config: %v", err))
  39. }
  40. if !path.IsAbs(vconfig.InboundConfig.File) && len(vconfig.InboundConfig.File) > 0 {
  41. vconfig.InboundConfig.File = path.Join(path.Dir(*configFile), vconfig.InboundConfig.File)
  42. }
  43. if !path.IsAbs(vconfig.OutboundConfig.File) && len(vconfig.OutboundConfig.File) > 0 {
  44. vconfig.OutboundConfig.File = path.Join(path.Dir(*configFile), vconfig.OutboundConfig.File)
  45. }
  46. vPoint, err := core.NewPoint(vconfig)
  47. if err != nil {
  48. panic(log.Error("Failed to create Point server: %v", err))
  49. }
  50. err = vPoint.Start()
  51. if err != nil {
  52. log.Error("Error starting Point server: %v", err)
  53. }
  54. finish := make(chan bool)
  55. <-finish
  56. }