fix(net/ghttp): improve GetMetaTag method to handle nil and type checks

This commit is contained in:
hailaz
2025-05-16 17:55:00 +08:00
parent 88c4471500
commit 9033ca087b

View File

@ -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 ""
}