V2bX/core/core.go

33 lines
547 B
Go
Raw Normal View History

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) {
if f, ok := cores[strings.ToLower(c.Type)]; ok {
return f(c)
} else {
return nil, errors.New("unknown core type")
2022-10-09 23:31:15 -04:00
}
}
2022-10-09 23:31:15 -04:00
func RegisterCore(t string, f func(c *conf.CoreConfig) (Core, error)) {
cores[t] = f
2022-10-09 23:31:15 -04:00
}
func RegisteredCore() []string {
cs := make([]string, 0, len(cores))
for k := range cores {
cs = append(cs, k)
}
return cs
}