mirror of
https://github.com/wyx2685/V2bX.git
synced 2026-02-04 04:30:08 +00:00
refactor conf
This commit is contained in:
19
core/core.go
19
core/core.go
@@ -11,16 +11,19 @@ var (
|
||||
cores = map[string]func(c *conf.CoreConfig) (Core, error){}
|
||||
)
|
||||
|
||||
func NewCore(c *conf.CoreConfig) (Core, error) {
|
||||
func NewCore(c []conf.CoreConfig) (Core, error) {
|
||||
if len(c) < 0 {
|
||||
return nil, errors.New("no have vail core")
|
||||
}
|
||||
// multi core
|
||||
if types := strings.Split(c.Type, " "); len(types) > 1 {
|
||||
if len(c) > 1 {
|
||||
var cs []Core
|
||||
for _, t := range types {
|
||||
f, ok := cores[strings.ToLower(t)]
|
||||
for _, t := range c {
|
||||
f, ok := cores[strings.ToLower(t.Type)]
|
||||
if !ok {
|
||||
return nil, errors.New("unknown core type: " + t)
|
||||
return nil, errors.New("unknown core type: " + t.Type)
|
||||
}
|
||||
core1, err := f(c)
|
||||
core1, err := f(&t)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -31,8 +34,8 @@ func NewCore(c *conf.CoreConfig) (Core, error) {
|
||||
}, nil
|
||||
}
|
||||
// one core
|
||||
if f, ok := cores[strings.ToLower(c.Type)]; ok {
|
||||
return f(c)
|
||||
if f, ok := cores[c[0].Type]; ok {
|
||||
return f(&c[0])
|
||||
} else {
|
||||
return nil, errors.New("unknown core type")
|
||||
}
|
||||
|
||||
@@ -20,4 +20,5 @@ type Core interface {
|
||||
GetUserTraffic(tag, uuid string, reset bool) (up int64, down int64)
|
||||
DelUsers(users []panel.UserInfo, tag string) error
|
||||
Protocols() []string
|
||||
Type() string
|
||||
}
|
||||
|
||||
@@ -39,12 +39,12 @@ func isSupported(protocol string, protocols []string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (s *Selector) AddNode(tag string, info *panel.NodeInfo, config *conf.Options) error {
|
||||
func (s *Selector) AddNode(tag string, info *panel.NodeInfo, option *conf.Options) error {
|
||||
for i := range s.cores {
|
||||
if !isSupported(info.Type, s.cores[i].Protocols()) {
|
||||
if option.Core != s.cores[i].Type() {
|
||||
continue
|
||||
}
|
||||
err := s.cores[i].AddNode(tag, info, config)
|
||||
err := s.cores[i].AddNode(tag, info, option)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -97,3 +97,7 @@ func (s *Selector) Protocols() []string {
|
||||
}
|
||||
return protocols
|
||||
}
|
||||
|
||||
func (s *Selector) Type() string {
|
||||
return "selector"
|
||||
}
|
||||
|
||||
@@ -271,3 +271,7 @@ func (b *Box) Protocols() []string {
|
||||
"hysteria",
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Box) Type() string {
|
||||
return "sing"
|
||||
}
|
||||
|
||||
@@ -194,3 +194,7 @@ func (c *Core) Protocols() []string {
|
||||
"trojan",
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Core) Type() string {
|
||||
return "xray"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user