improve package gmeta

This commit is contained in:
John Guo
2022-05-18 17:57:16 +08:00
parent c871bb3a1e
commit 6176028176

View File

@ -16,8 +16,8 @@ import (
type Meta struct{}
const (
// metaAttributeName is the attribute name of metadata in struct.
metaAttributeName = "Meta"
metaAttributeName = "Meta" // metaAttributeName is the attribute name of metadata in struct.
metaTypeName = "gmeta.Meta" // metaTypeName is for type string comparison.
)
// Data retrieves and returns all metadata from `object`.
@ -27,7 +27,9 @@ func Data(object interface{}) map[string]string {
return nil
}
if field, ok := reflectType.FieldByName(metaAttributeName); ok {
return gstructs.ParseTag(string(field.Tag))
if field.Type.String() == metaTypeName {
return gstructs.ParseTag(string(field.Tag))
}
}
return map[string]string{}
}