diff --git a/annotation/annotation.go b/annotation/annotation.go index bf8a774..cec8010 100644 --- a/annotation/annotation.go +++ b/annotation/annotation.go @@ -88,39 +88,39 @@ func splitAnnotation(s string) (map[string]string, error) { return ss, nil } -func splitAnnotationAttribute(s string) (map[string]string, error) { - ss := make(map[string]string, 0) - ts := s - for { - as := strings.Index(ts, AnnotationKeyValueSpliter) - if -1 == as { - break - } - aName := ts[:as] +// func splitAnnotationAttribute(s string) (map[string]string, error) { +// ss := make(map[string]string, 0) +// ts := s +// for { +// as := strings.Index(ts, AnnotationKeyValueSpliter) +// if -1 == as { +// break +// } +// aName := ts[:as] - aas := strings.Index(ts[as:], AnnotationAttributeStartChar) - aae := strings.Index(ts[as+aas+1:], AnnotationAttributeEndChar) +// aas := strings.Index(ts[as:], AnnotationAttributeStartChar) +// aae := strings.Index(ts[as+aas+1:], AnnotationAttributeEndChar) - if -1 == aas && -1 == aae { - ss[aName] = ts[as+1 : len(ts)] - } else if -1 != aas && -1 != aae { - ss[aName] = ts[as+aas+1 : as+aas+aae+1] - } else { - return nil, fmt.Errorf("not valid string %s", ts) - } +// if -1 == aas && -1 == aae { +// ss[aName] = ts[as+1 : len(ts)] +// } else if -1 != aas && -1 != aae { +// ss[aName] = ts[as+aas+1 : as+aas+aae+1] +// } else { +// return nil, fmt.Errorf("not valid string %s", ts) +// } - asi := strings.Index(ts[as+aae:], AnnotationAttributeSpliter) - if -1 == asi { - break - } - if len(ts) <= (as + aae + asi + 1) { - break - } - ts = strings.TrimSpace(ts[as+aae+asi+1:]) - } +// asi := strings.Index(ts[as+aae:], AnnotationAttributeSpliter) +// if -1 == asi { +// break +// } +// if len(ts) <= (as + aae + asi + 1) { +// break +// } +// ts = strings.TrimSpace(ts[as+aae+asi+1:]) +// } - return ss, nil -} +// return ss, nil +// } func newAnnotation(name string, attributes string) (reflect.Type, Annotation, error) { def, ok := annotationRegistry[name] diff --git a/annotation/annotation_test.go b/annotation/annotation_test.go index cccdb0c..8c7a012 100644 --- a/annotation/annotation_test.go +++ b/annotation/annotation_test.go @@ -12,9 +12,9 @@ func TestSplitAnnotation(t *testing.T) { log.Printf("%v", ss) } -func TestSplitAnnotationAttribute(t *testing.T) { - s := "method='POST', entry='/account/signin', params='[signinID, signinPW]'" - ss, _ := splitAnnotationAttribute(s) +// func TestSplitAnnotationAttribute(t *testing.T) { +// s := "method='POST', entry='/account/signin', params='[signinID, signinPW]'" +// ss, _ := splitAnnotationAttribute(s) - log.Printf("%v", ss) -} +// log.Printf("%v", ss) +// } diff --git a/annotation/meta.go b/annotation/meta.go index d478ea1..88b4bb8 100644 --- a/annotation/meta.go +++ b/annotation/meta.go @@ -3,8 +3,6 @@ package annotation import ( "reflect" "strings" - - cur "git.loafle.net/commons/util-go/reflect" ) type AnnotationFieldMeta struct { @@ -33,35 +31,35 @@ func (o anotationMetaOptions) Contains(optionName string) bool { return false } -func getMetaFields(t reflect.Type) map[string]*AnnotationFieldMeta { - fields := make(map[string]*AnnotationFieldMeta, 0) - rt, _, _ := cur.GetTypeInfo(t) - if reflect.Struct != rt.Kind() { - return fields - } +// func getMetaFields(t reflect.Type) map[string]*AnnotationFieldMeta { +// fields := make(map[string]*AnnotationFieldMeta, 0) +// rt, _, _ := cur.GetTypeInfo(t) +// if reflect.Struct != rt.Kind() { +// return fields +// } - for i := 0; i < rt.NumField(); i++ { - f := rt.Field(i) +// for i := 0; i < rt.NumField(); i++ { +// f := rt.Field(i) - if f.Anonymous { - pFields := getMetaFields(f.Type) - for k, v := range pFields { - fields[k] = v - } - } else { - name, metaOptions := parseAnnotationMeta(f.Tag) - if "" == name { - continue - } - fields[name] = &AnnotationFieldMeta{ - fieldName: f.Name, - options: metaOptions, - } - } - } +// if f.Anonymous { +// pFields := getMetaFields(f.Type) +// for k, v := range pFields { +// fields[k] = v +// } +// } else { +// name, metaOptions := parseAnnotationMeta(f.Tag) +// if "" == name { +// continue +// } +// fields[name] = &AnnotationFieldMeta{ +// fieldName: f.Name, +// options: metaOptions, +// } +// } +// } - return fields -} +// return fields +// } func parseAnnotationMeta(tag reflect.StructTag) (string, anotationMetaOptions) { s := strings.Trim(tag.Get(AnnotationMetaTag), " ") @@ -75,97 +73,3 @@ func parseAnnotationMeta(tag reflect.StructTag) (string, anotationMetaOptions) { return s, anotationMetaOptions("") } - -// func setMetaAttributes(def *AnnotationDefinition, rv reflect.Value, attributes map[string]string) { -// META_LOOP: -// for k, v := range attributes { -// meta := def.fields[k] -// if nil == meta { -// log.Printf("Attribute[%s] of Type[%s] is not exist", k, def.rt.Name()) -// continue META_LOOP -// } -// f := rv.FieldByName(meta.fieldName) - -// switch f.Type().Kind() { -// case reflect.Array: -// log.Printf("Array not support") -// case reflect.Slice: -// s, err := convertSlice(v, f.Type()) -// if nil != err { -// continue META_LOOP -// } -// f.Set(reflect.ValueOf(s)) -// case reflect.Map: -// s, err := convertMap(v, f.Type()) -// if nil != err { -// continue META_LOOP -// } -// f.Set(reflect.ValueOf(s)) -// case reflect.Struct: -// log.Printf("Struct not support") -// case reflect.Ptr: -// log.Printf("Pointer not support") -// default: -// f.Set(reflect.ValueOf(v)) -// } -// } -// } - -// func convertSlice(s string, t reflect.Type) (interface{}, error) { -// ts := s - -// as := strings.Index(ts, AnnotationAttributeArrayStartChar) -// if -1 == as { -// return nil, fmt.Errorf("Value is not contain %s", AnnotationAttributeArrayStartChar) -// } -// ts = ts[as+1:] -// ae := strings.Index(ts, AnnotationAttributeArrayEndChar) -// if -1 == ae { -// return nil, fmt.Errorf("Value is not contain %s", AnnotationAttributeArrayEndChar) -// } -// ts = ts[:ae] - -// is := strings.Split(ts, AnnotationAttributeArrayItemSpliter) -// if nil == is || 0 == len(is) { -// return nil, nil -// } - -// for i, v := range is { -// is[i] = strings.TrimSpace(v) -// } - -// return cur.ConvertToType(is, t) -// } - -// func convertMap(s string, t reflect.Type) (interface{}, error) { -// ts := s - -// as := strings.Index(ts, AnnotationAttributeMapStartChar) -// if -1 == as { -// return nil, fmt.Errorf("Value is not contain %s", AnnotationAttributeMapStartChar) -// } -// ts = ts[as+1:] -// ae := strings.Index(ts, AnnotationAttributeMapEndChar) -// if -1 == ae { -// return nil, fmt.Errorf("Value is not contain %s", AnnotationAttributeMapEndChar) -// } -// ts = ts[:ae] - -// is := strings.Split(ts, AnnotationAttributeMapItemSpliter) -// if nil == is || 0 == len(is) { -// return nil, nil -// } - -// ms := make(map[string]string) -// for _, s := range is { -// kvs := strings.Split(s, AnnotationAttributeMapKeyValueSpliter) -// if 2 != len(kvs) { -// return nil, fmt.Errorf("Map Value format k:v but %s", s) -// } -// k := strings.TrimSpace(kvs[0]) -// v := strings.TrimSpace(kvs[1]) -// ms[k] = v -// } - -// return cur.ConvertToType(ms, t) -// }