Selaa lähdekoodia

assign tag扩充

yjp 1 vuosi sitten
vanhempi
commit
681ed46bad
1 muutettua tiedostoa jossa 9 lisäystä ja 0 poistoa
  1. 9 0
      framwork/tag/assign/tag.go

+ 9 - 0
framwork/tag/assign/tag.go

@@ -19,6 +19,7 @@ const (
 const (
 	tagKey            = "assign"
 	tagPartIgnore     = "-"
+	tagPartToStruct   = "toStruct"
 	tagPartToField    = "toField"
 	tagPartParseTime  = "parseTime"
 	tagPartFormatTime = "formatTime"
@@ -30,6 +31,7 @@ const (
 )
 
 type Tag struct {
+	ToStruct   string
 	ToField    string
 	ParseTime  string
 	FormatTime string
@@ -78,6 +80,10 @@ func parseTag(fromElemValue reflect.Value, toElemValue *reflect.Value, onParsedF
 			continue
 		}
 
+		if strutils.IsStringNotEmpty(tag.ToStruct) && toElemValue.Type().String() != tag.ToStruct {
+			continue
+		}
+
 		toFieldValue := toElemValue.FieldByName(tag.ToField)
 
 		// 不存在对应的字段
@@ -118,6 +124,7 @@ func parseFieldTag(field reflect.StructField, tagStr string) (*Tag, error) {
 	}
 
 	tag := &Tag{
+		ToStruct:   "",
 		ToField:    field.Name,
 		ParseTime:  time.DateTime,
 		FormatTime: time.DateTime,
@@ -141,6 +148,8 @@ func parseFieldTag(field reflect.StructField, tagStr string) (*Tag, error) {
 			}
 
 			switch tagPartKeyValue[0] {
+			case tagPartToStruct:
+				tag.ToStruct = tagPartKeyValue[1]
 			case tagPartToField:
 				tag.ToField = tagPartKeyValue[1]
 			case tagPartParseTime: