mirror of
https://gitee.com/johng/gf
synced 2026-06-06 02:25:47 +08:00
fix(net/ghttp): improve GetMetaTag method to handle nil and type checks
This commit is contained in:
@ -294,12 +294,11 @@ func (h *HandlerItemParsed) MarshalJSON() ([]byte, error) {
|
||||
// GetMetaTag retrieves and returns the metadata value associated with the given key from the request struct.
|
||||
// The meta value is from struct tags from g.Meta/gmeta.Meta type.
|
||||
func (h *HandlerItem) GetMetaTag(key string) string {
|
||||
if h == nil {
|
||||
return ""
|
||||
}
|
||||
metaValue := gmeta.Get(h.Info.Type.In(1), key)
|
||||
if metaValue != nil {
|
||||
return metaValue.String()
|
||||
if h != nil && h.Info.Type != nil && h.Info.Type.NumIn() == 2 {
|
||||
metaValue := gmeta.Get(h.Info.Type.In(1), key)
|
||||
if metaValue != nil {
|
||||
return metaValue.String()
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user