代码拉取完成,页面将自动刷新
package reflectutils
import (
"github.com/emirpasic/gods/maps/linkedhashmap"
"github.com/sirupsen/logrus"
"reflect"
)
const TAG_ENV = "env"
const TAG_JSON = "json"
const TAG_GROM = "gorm"
type ReflectTags struct {
tagMap *linkedhashmap.Map `json:"tag_map"`
}
func NewReflectTags() *ReflectTags {
return &ReflectTags{
tagMap: linkedhashmap.New(),
}
}
func (this *ReflectTags) TagMap() *linkedhashmap.Map {
return this.tagMap
}
func (this *ReflectTags) SetTagMap(tagMap *linkedhashmap.Map) {
this.tagMap = tagMap
}
func (this *ReflectTags) ParseOne(v any, FieldName string, tagName string) {
elem := reflect.TypeOf(v).Elem()
structField, _ := elem.FieldByName(FieldName)
this.tagMap.Put(FieldName, structField.Tag.Get(tagName))
}
func (this *ReflectTags) ToString() string {
v, _ := this.tagMap.ToJSON()
return string(v)
}
func (this *ReflectTags) Log() {
this.tagMap.Each(func(key interface{}, value interface{}) {
logrus.Info(key, value)
})
this.tagMap.Map(func(key1 interface{}, value1 interface{}) (interface{}, interface{}) {
return key1, value1
})
}
func (this *ReflectTags) ParseGorm(v any) {
this.Parse(TAG_GROM, v)
}
func (this *ReflectTags) ParseJson(v any) {
this.Parse(TAG_JSON, v)
}
func (this *ReflectTags) ParseEnv(v any) {
this.Parse(TAG_ENV, v)
}
func (this *ReflectTags) Parse(key string, v any) {
elem := reflect.TypeOf(v).Elem()
for i := 0; i < elem.NumField(); i++ {
structField := elem.Field(i)
var tag = structField.Tag.Get(key)
this.tagMap.Put(structField.Name, tag)
logrus.Info(this.tagMap)
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。