mirror of
https://github.com/v2ray/v2ray-core.git
synced 2026-11-14 14:47:12 +00:00
merge similar error definitions
This commit is contained in:
8 files changed
+27
-30
No files matched your search
@@ -1,15 +1,13 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/v2ray/v2ray-core/common"
|
||||
)
|
||||
|
||||
type ConfigObjectCreator func([]byte) (interface{}, error)
|
||||
|
||||
var (
|
||||
configCache map[string]ConfigObjectCreator
|
||||
|
||||
ErrRouterNotFound = errors.New("Router not found.")
|
||||
)
|
||||
|
||||
func RegisterRouterConfig(strategy string, creator ConfigObjectCreator) error {
|
||||
@@ -21,7 +19,7 @@ func RegisterRouterConfig(strategy string, creator ConfigObjectCreator) error {
|
||||
func CreateRouterConfig(strategy string, data []byte) (interface{}, error) {
|
||||
creator, found := configCache[strategy]
|
||||
if !found {
|
||||
return nil, ErrRouterNotFound
|
||||
return nil, common.ErrObjectNotFound
|
||||
}
|
||||
return creator(data)
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package router
|
||||
import (
|
||||
"github.com/v2ray/v2ray-core/app"
|
||||
"github.com/v2ray/v2ray-core/common"
|
||||
"github.com/v2ray/v2ray-core/common/log"
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
)
|
||||
|
||||
@@ -24,7 +25,9 @@ var (
|
||||
)
|
||||
|
||||
func RegisterRouter(name string, factory RouterFactory) error {
|
||||
// TODO: check name
|
||||
if _, found := routerCache[name]; found {
|
||||
return common.ErrDuplicatedName
|
||||
}
|
||||
routerCache[name] = factory
|
||||
return nil
|
||||
}
|
||||
@@ -33,5 +36,6 @@ func CreateRouter(name string, rawConfig interface{}, space app.Space) (Router,
|
||||
if factory, found := routerCache[name]; found {
|
||||
return factory.Create(rawConfig, space)
|
||||
}
|
||||
return nil, ErrRouterNotFound
|
||||
log.Error("Router: not found: ", name)
|
||||
return nil, common.ErrObjectNotFound
|
||||
}
|
||||
Reference in new issue
Block a user