mirror of https://github.com/v2ray/v2ray-core
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.1 KiB
46 lines
1.1 KiB
package json
|
|
|
|
import (
|
|
"github.com/v2ray/v2ray-core/proxy/common/config"
|
|
)
|
|
|
|
type ConfigObjectCreator func() interface{}
|
|
|
|
var (
|
|
configCache 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()
|
|
}
|
|
|
|
func initializeConfigCache() {
|
|
configCache = make(map[string]ConfigObjectCreator)
|
|
}
|
|
|
|
func init() {
|
|
initializeConfigCache()
|
|
}
|