From dc36d262ae32c0958ac5ae1bc486908e75022dd1 Mon Sep 17 00:00:00 2001 From: crusader Date: Wed, 21 Mar 2018 21:33:53 +0900 Subject: [PATCH] ing --- registry/registry.go | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/registry/registry.go b/registry/registry.go index 39684b3..e72e945 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -19,7 +19,7 @@ func init() { var registry ComponentRegistry type ComponentRegistry interface { - RegisterType(t reflect.Type) error + RegisterType(t reflect.Type) RegisterResource(name string, resource interface{}) error GetInstance(t reflect.Type) (interface{}, error) @@ -45,30 +45,30 @@ type defaultComponentRegistry struct { resourceByName map[string]interface{} } -func RegisterType(t reflect.Type) error { +func RegisterType(t reflect.Type) { pc, _, _, ok := runtime.Caller(1) details := runtime.FuncForPC(pc) if ok && details != nil { log.Printf("called from %s", details.Name()) } - return registry.RegisterType(t) + registry.RegisterType(t) } -func (cr *defaultComponentRegistry) RegisterType(t reflect.Type) error { +func (cr *defaultComponentRegistry) RegisterType(t reflect.Type) { if nil == t { - return fmt.Errorf("DI: t[reflect.Type] is nil") + log.Panicf("DI: t[reflect.Type] is nil") } if !cur.IsTypeKind(t, reflect.Struct, true) { - return fmt.Errorf("DI: t[reflect.Type] must be specified but is %v", t) + log.Panicf("DI: t[reflect.Type] must be specified but is %v", t) } td, err := cr.buildDefinition(t) if nil != err { - return fmt.Errorf("DI: %v", err) + log.Panicf("DI: %v", err) } if _, ok := cr.definitionByType[td.RealType]; ok { - return fmt.Errorf("DI: The type[%s] of Component is exist already", td.FullName) + log.Panicf("DI: The type[%s] of Component is exist already", td.FullName) } cr.definitionByType[td.RealType] = td @@ -82,11 +82,9 @@ func (cr *defaultComponentRegistry) RegisterType(t reflect.Type) error { } if eTD, ok := cr.definitionByName[name]; ok { - return fmt.Errorf("DI: The name[%s] of Component is exist already type[%s]", name, eTD.FullName) + log.Panicf("DI: The name[%s] of Component is exist already type[%s]", name, eTD.FullName) } cr.definitionByName[name] = td - - return nil } func RegisterResource(name string, resource interface{}) error {