github.com/MerlinKodo/sing-shadowsocks2@v0.1.6/cipher/method_registry.go (about) 1 package cipher 2 3 import ( 4 "context" 5 6 E "github.com/sagernet/sing/common/exceptions" 7 ) 8 9 var methodRegistry map[string]MethodCreator 10 11 func RegisterMethod(methods []string, creator MethodCreator) { 12 if methodRegistry == nil { 13 methodRegistry = make(map[string]MethodCreator) 14 } 15 for _, method := range methods { 16 methodRegistry[method] = creator 17 } 18 } 19 20 func CreateMethod(ctx context.Context, methodName string, options MethodOptions) (Method, error) { 21 if methodRegistry == nil { 22 methodRegistry = make(map[string]MethodCreator) 23 } 24 creator, ok := methodRegistry[methodName] 25 if !ok { 26 return nil, E.New("unknown method: ", methodName) 27 } 28 return creator(ctx, methodName, options) 29 }