This commit is contained in:
crusader 2018-04-07 01:59:06 +09:00
parent 52ae4371ce
commit 90836c801b

View File

@ -25,7 +25,7 @@ type ComponentRegistry interface {
GetInstance(t reflect.Type) (interface{}, error) GetInstance(t reflect.Type) (interface{}, error)
GetInstances(ts []reflect.Type) ([]interface{}, error) GetInstances(ts []reflect.Type) ([]interface{}, error)
GetInstanceByName(name string) (interface{}, error) GetInstanceByName(name string) (interface{}, error)
GetInstancesByAnnotationName(n string) ([]interface{}, error) // GetInstancesByAnnotationName(n string) ([]interface{}, error)
GetInstancesByAnnotationType(t reflect.Type) ([]interface{}, error) GetInstancesByAnnotationType(t reflect.Type) ([]interface{}, error)
} }
@ -215,27 +215,27 @@ func (cr *defaultComponentRegistry) GetInstances(ts []reflect.Type) ([]interface
// GetInstancesByAnnotationName returns instance of annotated // GetInstancesByAnnotationName returns instance of annotated
// n must be name of registered annotation // n must be name of registered annotation
func GetInstancesByAnnotationName(n string) ([]interface{}, error) { // func GetInstancesByAnnotationName(n string) ([]interface{}, error) {
return registry.GetInstancesByAnnotationName(n) // return registry.GetInstancesByAnnotationName(n)
} // }
func (cr *defaultComponentRegistry) GetInstancesByAnnotationName(n string) ([]interface{}, error) { // func (cr *defaultComponentRegistry) GetInstancesByAnnotationName(n string) ([]interface{}, error) {
var ( // var (
i interface{} // i interface{}
err error // err error
) // )
instances := make([]interface{}, 0) // instances := make([]interface{}, 0)
for _, td := range cr.definitionByType { // for _, td := range cr.definitionByType {
if nil != td.GetAnnotation(n) { // if nil != td.GetAnnotation(n) {
if i, err = cr.GetInstance(td.Type); nil != err { // if i, err = cr.GetInstance(td.Type); nil != err {
return nil, err // return nil, err
} // }
instances = append(instances, i) // instances = append(instances, i)
} // }
} // }
return instances, nil // return instances, nil
} // }
func GetInstancesByAnnotationType(t reflect.Type) ([]interface{}, error) { func GetInstancesByAnnotationType(t reflect.Type) ([]interface{}, error) {
return registry.GetInstancesByAnnotationType(t) return registry.GetInstancesByAnnotationType(t)