mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-21 01:27:03 -05:00
hide server implementation detail
This commit is contained in:
parent
6363c33790
commit
722594cb79
10
main/main.go
10
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()
|
||||
}
|
||||
|
34
v2ray.go
34
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.")
|
||||
|
Loading…
Reference in New Issue
Block a user