Move config cache to proxy/common

This commit is contained in:
V2Ray committed 2015-10-30 22:42:24 +01:00
1 parent c56e17fff9
commit 2b45e63607
14 files changed
+80 -58

No files matched your search

+9
View File
@@ -0,0 +1,9 @@
package config
import (
"errors"
)
var (
BadConfiguration = errors.New("Bad proxy configuration.")
)
+37
View File
@@ -0,0 +1,37 @@
package json
import (
"github.com/v2ray/v2ray-core/proxy/common/config"
)
type ConfigObjectCreator func() interface{}
var (
configCache = make(map[string]ConfigObjectCreator)
)
func getConfigKey(protocol string, cType config.Type) string {
return protocol + "_" + string(cType)
}
func registerConfigType(protocol string, cType config.Type, creator ConfigObjectCreator) error {
// TODO: check name
configCache[getConfigKey(protocol, cType)] = creator
return nil
}
func RegisterInboundConnectionConfig(protocol string, creator ConfigObjectCreator) error {
return registerConfigType(protocol, config.TypeInbound, creator)
}
func RegisterOutboundConnectionConfig(protocol string, creator ConfigObjectCreator) error {
return registerConfigType(protocol, config.TypeOutbound, creator)
}
func CreateConfig(protocol string, cType config.Type) interface{} {
creator, found := configCache[getConfigKey(protocol, cType)]
if !found {
return nil
}
return creator()
}
+8
View File
@@ -0,0 +1,8 @@
package config
type Type string
const (
TypeInbound = Type("inbound")
TypeOutbound = Type("outbound")
)