diff --git a/main/main.go b/main/main.go index 5c0fb6714..192e58b78 100644 --- a/main/main.go +++ b/main/main.go @@ -43,7 +43,7 @@ func GetConfigFormat() core.ConfigFormat { } } -func startV2Ray() (*core.Point, error) { +func startV2Ray() (core.Server, error) { if len(configFile) == 0 { return nil, errors.New("V2Ray: Config file is not set.") } @@ -64,7 +64,7 @@ func startV2Ray() (*core.Point, error) { return nil, errors.Base(err).Message("V2Ray: Failed to read config file: ", configFile) } - vPoint, err := core.NewPoint(config) + vPoint, err := core.New(config) if err != nil { return nil, errors.Base(err).Message("V2Ray: Failed to create initialize.") } @@ -81,7 +81,7 @@ func main() { return } - point, err := startV2Ray() + server, err := startV2Ray() if err != nil { fmt.Println(err.Error()) return @@ -92,7 +92,7 @@ func main() { return } - if err := point.Start(); err != nil { + if err := server.Start(); err != nil { fmt.Println("V2Ray: Failed to start. ", err) } @@ -100,5 +100,5 @@ func main() { signal.Notify(osSignals, os.Interrupt, os.Kill, syscall.SIGTERM) <-osSignals - point.Close() + server.Close() } diff --git a/v2ray.go b/v2ray.go index 74ac10a81..ad13f3997 100644 --- a/v2ray.go +++ b/v2ray.go @@ -23,20 +23,20 @@ type Server interface { Close() } -// Point shell of V2Ray. -type Point struct { +// New creates a new V2Ray server with given config. +func New(config *Config) (Server, error) { + return newSimpleServer(config) +} + +// simpleServer shell of V2Ray. +type simpleServer struct { space app.Space } -// New creates a new V2Ray server with given config. -func New(config *Config) (Server, error) { - return NewPoint(config) -} - -// NewPoint returns a new Point server based on given configuration. +// newSimpleServer returns a new Point server based on given configuration. // The server is not started at this point. -func NewPoint(config *Config) (*Point, error) { - var pt = new(Point) +func newSimpleServer(config *Config) (*simpleServer, error) { + var server = new(simpleServer) if err := config.Transport.Apply(); err != nil { return nil, err @@ -45,7 +45,7 @@ func NewPoint(config *Config) (*Point, error) { space := app.NewSpace() ctx := app.ContextWithSpace(context.Background(), space) - pt.space = space + server.space = space for _, appSettings := range config.App { settings, err := appSettings.GetInstance() @@ -132,19 +132,19 @@ func NewPoint(config *Config) (*Point, error) { } } - if err := pt.space.Initialize(); err != nil { + if err := server.space.Initialize(); err != nil { return nil, err } - return pt, nil + return server, nil } -func (v *Point) Close() { - v.space.Close() +func (s *simpleServer) Close() { + s.space.Close() } -func (v *Point) Start() error { - if err := v.space.Start(); err != nil { +func (s *simpleServer) Start() error { + if err := s.space.Start(); err != nil { return err } log.Warning("V2Ray started.")