di/annotation/definition.go

41 lines
713 B
Go
Raw Permalink Normal View History

2018-03-15 13:19:44 +00:00
package annotation
import (
2018-03-15 14:38:47 +00:00
"fmt"
2018-03-15 13:19:44 +00:00
"reflect"
2018-03-20 02:43:00 +00:00
cur "git.loafle.net/commons_go/util/reflect"
2018-03-15 13:19:44 +00:00
)
var annotationRegistry map[string]*AnnotationDefinition
func init() {
annotationRegistry = make(map[string]*AnnotationDefinition, 0)
}
2018-03-21 09:28:21 +00:00
func RegisterAnnotation(name string, t reflect.Type) error {
2018-03-15 14:38:47 +00:00
if _, ok := annotationRegistry[name]; ok {
2018-03-21 09:28:21 +00:00
return fmt.Errorf("DI: name[%s] of annotation exist already", name)
2018-03-15 14:38:47 +00:00
}
2018-03-15 13:19:44 +00:00
meta := getMetaFields(t)
2018-03-20 02:43:00 +00:00
fRT, _, _ := cur.GetTypeInfo(t)
2018-03-15 13:19:44 +00:00
def := &AnnotationDefinition{
t: t,
rt: fRT,
fields: meta,
}
annotationRegistry[name] = def
2018-03-21 09:28:21 +00:00
return nil
2018-03-15 13:19:44 +00:00
}
type AnnotationDefinition struct {
t reflect.Type
rt reflect.Type
fields map[string]*AnnotationFieldMeta
}