forked from InazumaV/V2bX
-
Notifications
You must be signed in to change notification settings - Fork 196
/
Copy pathcore.go
51 lines (45 loc) · 933 Bytes
/
core.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package core
import (
"errors"
"strings"
"github.com/Yuzuki616/V2bX/conf"
)
var (
cores = map[string]func(c *conf.CoreConfig) (Core, error){}
)
func NewCore(c *conf.CoreConfig) (Core, error) {
// multi core
if types := strings.Split(c.Type, " "); len(types) > 1 {
var cs []Core
for _, t := range types {
f, ok := cores[strings.ToLower(c.Type)]
if !ok {
return nil, errors.New("unknown core type: " + t)
}
core1, err := f(c)
if err != nil {
return nil, err
}
cs = append(cs, core1)
}
return &Selector{
cores: cs,
}, nil
}
// one core
if f, ok := cores[strings.ToLower(c.Type)]; ok {
return f(c)
} else {
return nil, errors.New("unknown core type")
}
}
func RegisterCore(t string, f func(c *conf.CoreConfig) (Core, error)) {
cores[t] = f
}
func RegisteredCore() []string {
cs := make([]string, 0, len(cores))
for k := range cores {
cs = append(cs, k)
}
return cs
}