mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-30 05:56:54 -05:00
comments
This commit is contained in:
parent
7b707275df
commit
10acab0dfe
@ -6,13 +6,15 @@ import (
|
||||
"reflect"
|
||||
)
|
||||
|
||||
type creator func(ctx context.Context, config interface{}) (interface{}, error)
|
||||
// ConfigCreator is a function to create an object by a config.
|
||||
type ConfigCreator func(ctx context.Context, config interface{}) (interface{}, error)
|
||||
|
||||
var (
|
||||
typeCreatorRegistry = make(map[reflect.Type]creator)
|
||||
typeCreatorRegistry = make(map[reflect.Type]ConfigCreator)
|
||||
)
|
||||
|
||||
func RegisterConfig(config interface{}, configCreator creator) error {
|
||||
// RegisterConfig registers a global config creator. The config can be nil but must have a type.
|
||||
func RegisterConfig(config interface{}, configCreator ConfigCreator) error {
|
||||
configType := reflect.TypeOf(config)
|
||||
if _, found := typeCreatorRegistry[configType]; found {
|
||||
return errors.New("Common: " + configType.Name() + " is already registered.")
|
||||
@ -21,6 +23,7 @@ func RegisterConfig(config interface{}, configCreator creator) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// CreateObject creates an object by its config. The config type must be registered through RegisterConfig().
|
||||
func CreateObject(ctx context.Context, config interface{}) (interface{}, error) {
|
||||
configType := reflect.TypeOf(config)
|
||||
creator, found := typeCreatorRegistry[configType]
|
||||
|
@ -1,4 +1,8 @@
|
||||
// Package proxy contains all proxies used by V2Ray.
|
||||
//
|
||||
// To implement an inbound or outbound proxy, one needs to do the following:
|
||||
// 1. Implement the interface(s) below.
|
||||
// 2. Register a config creator through common.RegisterConfig.
|
||||
package proxy
|
||||
|
||||
import (
|
||||
|
Loading…
Reference in New Issue
Block a user