merge similar error definitions

This commit is contained in:
v2ray committed 2016-08-18 08:34:21 +02:00
1 parent 786775ea80
commit ad1353ac2f
8 files changed
+27 -30

No files matched your search

+2 -4
View File
@@ -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)
}
+6 -2
View File
@@ -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
}