|
@@ -9,20 +9,20 @@ type implementationRegistry struct {
|
|
|
implSet map[string]*implementationSet
|
|
implSet map[string]*implementationSet
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (i *implementationRegistry) RegisterImplementation(name string, opt *protoext.MessageOpt) {
|
|
|
|
|
|
|
+func (i *implementationRegistry) RegisterImplementation(name string, opt *protoext.MessageOpt, loader CustomLoader) {
|
|
|
interfaceType := opt.GetType()[0]
|
|
interfaceType := opt.GetType()[0]
|
|
|
implSet, found := i.implSet[interfaceType]
|
|
implSet, found := i.implSet[interfaceType]
|
|
|
if !found {
|
|
if !found {
|
|
|
implSet = newImplementationSet()
|
|
implSet = newImplementationSet()
|
|
|
i.implSet[interfaceType] = implSet
|
|
i.implSet[interfaceType] = implSet
|
|
|
}
|
|
}
|
|
|
- implSet.RegisterImplementation(name, opt)
|
|
|
|
|
|
|
+ implSet.RegisterImplementation(name, opt, loader)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (i *implementationRegistry) FindImplementationByAlias(interfaceType, alias string) (string, error) {
|
|
|
|
|
|
|
+func (i *implementationRegistry) FindImplementationByAlias(interfaceType, alias string) (string, CustomLoader, error) {
|
|
|
implSet, found := i.implSet[interfaceType]
|
|
implSet, found := i.implSet[interfaceType]
|
|
|
if !found {
|
|
if !found {
|
|
|
- return "", newError("cannot find implemention unknown interface type")
|
|
|
|
|
|
|
+ return "", nil, newError("cannot find implemention unknown interface type")
|
|
|
}
|
|
}
|
|
|
return implSet.FindImplementationByAlias(alias)
|
|
return implSet.FindImplementationByAlias(alias)
|
|
|
}
|
|
}
|
|
@@ -33,17 +33,19 @@ func newImplementationRegistry() *implementationRegistry {
|
|
|
|
|
|
|
|
var globalImplementationRegistry = newImplementationRegistry()
|
|
var globalImplementationRegistry = newImplementationRegistry()
|
|
|
|
|
|
|
|
-func RegisterImplementation(proto proto.Message) error {
|
|
|
|
|
|
|
+// RegisterImplementation register an implementation of a type of interface
|
|
|
|
|
+// loader(CustomLoader) is a private API, its interface is subject to breaking changes
|
|
|
|
|
+func RegisterImplementation(proto proto.Message, loader CustomLoader) error {
|
|
|
msgDesc := proto.ProtoReflect().Type().Descriptor()
|
|
msgDesc := proto.ProtoReflect().Type().Descriptor()
|
|
|
fullName := string(msgDesc.FullName())
|
|
fullName := string(msgDesc.FullName())
|
|
|
msgOpts, err := protoext.GetMessageOptions(msgDesc)
|
|
msgOpts, err := protoext.GetMessageOptions(msgDesc)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return newError("unable to find message options").Base(err)
|
|
return newError("unable to find message options").Base(err)
|
|
|
}
|
|
}
|
|
|
- globalImplementationRegistry.RegisterImplementation(fullName, msgOpts)
|
|
|
|
|
|
|
+ globalImplementationRegistry.RegisterImplementation(fullName, msgOpts, loader)
|
|
|
return nil
|
|
return nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func FindImplementationByAlias(interfaceType, alias string) (string, error) {
|
|
|
|
|
|
|
+func FindImplementationByAlias(interfaceType, alias string) (string, CustomLoader, error) {
|
|
|
return globalImplementationRegistry.FindImplementationByAlias(interfaceType, alias)
|
|
return globalImplementationRegistry.FindImplementationByAlias(interfaceType, alias)
|
|
|
}
|
|
}
|