1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-30 05:56:54 -05:00

hide server implementation detail

This commit is contained in:
Darien Raymond 2017-02-22 11:30:52 +01:00
parent 6363c33790
commit 722594cb79
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
2 changed files with 22 additions and 22 deletions

View File

@ -43,7 +43,7 @@ func GetConfigFormat() core.ConfigFormat {
} }
} }
func startV2Ray() (*core.Point, error) { func startV2Ray() (core.Server, error) {
if len(configFile) == 0 { if len(configFile) == 0 {
return nil, errors.New("V2Ray: Config file is not set.") 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) 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 { if err != nil {
return nil, errors.Base(err).Message("V2Ray: Failed to create initialize.") return nil, errors.Base(err).Message("V2Ray: Failed to create initialize.")
} }
@ -81,7 +81,7 @@ func main() {
return return
} }
point, err := startV2Ray() server, err := startV2Ray()
if err != nil { if err != nil {
fmt.Println(err.Error()) fmt.Println(err.Error())
return return
@ -92,7 +92,7 @@ func main() {
return return
} }
if err := point.Start(); err != nil { if err := server.Start(); err != nil {
fmt.Println("V2Ray: Failed to start. ", err) fmt.Println("V2Ray: Failed to start. ", err)
} }
@ -100,5 +100,5 @@ func main() {
signal.Notify(osSignals, os.Interrupt, os.Kill, syscall.SIGTERM) signal.Notify(osSignals, os.Interrupt, os.Kill, syscall.SIGTERM)
<-osSignals <-osSignals
point.Close() server.Close()
} }

View File

@ -23,20 +23,20 @@ type Server interface {
Close() Close()
} }
// Point shell of V2Ray. // New creates a new V2Ray server with given config.
type Point struct { func New(config *Config) (Server, error) {
return newSimpleServer(config)
}
// simpleServer shell of V2Ray.
type simpleServer struct {
space app.Space space app.Space
} }
// New creates a new V2Ray server with given config. // newSimpleServer returns a new Point server based on given configuration.
func New(config *Config) (Server, error) {
return NewPoint(config)
}
// NewPoint returns a new Point server based on given configuration.
// The server is not started at this point. // The server is not started at this point.
func NewPoint(config *Config) (*Point, error) { func newSimpleServer(config *Config) (*simpleServer, error) {
var pt = new(Point) var server = new(simpleServer)
if err := config.Transport.Apply(); err != nil { if err := config.Transport.Apply(); err != nil {
return nil, err return nil, err
@ -45,7 +45,7 @@ func NewPoint(config *Config) (*Point, error) {
space := app.NewSpace() space := app.NewSpace()
ctx := app.ContextWithSpace(context.Background(), space) ctx := app.ContextWithSpace(context.Background(), space)
pt.space = space server.space = space
for _, appSettings := range config.App { for _, appSettings := range config.App {
settings, err := appSettings.GetInstance() 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 nil, err
} }
return pt, nil return server, nil
} }
func (v *Point) Close() { func (s *simpleServer) Close() {
v.space.Close() s.space.Close()
} }
func (v *Point) Start() error { func (s *simpleServer) Start() error {
if err := v.space.Start(); err != nil { if err := s.space.Start(); err != nil {
return err return err
} }
log.Warning("V2Ray started.") log.Warning("V2Ray started.")