feat(net/ghttp): add Request.GetMetaTag to retrieve specific meta tag value (#4185)

This commit is contained in:
PandaPy
2025-03-09 11:17:41 +08:00
committed by GitHub
parent bcda48bf82
commit f8331bad6e
6 changed files with 96 additions and 15 deletions

View File

@ -36,7 +36,7 @@ type Field struct {
type FieldsInput struct {
// Pointer should be type of struct/*struct.
// TODO this attribute name is not suitable, which would make confuse.
Pointer interface{}
Pointer any
// RecursiveOption specifies the way retrieving the fields recursively if the attribute
// is an embedded struct. It is RecursiveOptionNone in default.
@ -47,7 +47,7 @@ type FieldsInput struct {
type FieldMapInput struct {
// Pointer should be type of struct/*struct.
// TODO this attribute name is not suitable, which would make confuse.
Pointer interface{}
Pointer any
// PriorityTagArray specifies the priority tag array for retrieving from high to low.
// If it's given `nil`, it returns map[name]Field, of which the `name` is attribute name.
@ -123,6 +123,7 @@ func Fields(in FieldsInput) ([]Field, error) {
}
}
continue
default:
}
}
continue
@ -194,6 +195,7 @@ func FieldMap(in FieldMapInput) (map[string]Field, error) {
mapField[k] = tempV
}
}
default:
}
} else {
mapField[field.Name()] = tempField
@ -205,7 +207,19 @@ func FieldMap(in FieldMapInput) (map[string]Field, error) {
// StructType retrieves and returns the struct Type of specified struct/*struct.
// The parameter `object` should be either type of struct/*struct/[]struct/[]*struct.
func StructType(object interface{}) (*Type, error) {
func StructType(object any) (*Type, error) {
// if already reflect.Type
if reflectType, ok := object.(reflect.Type); ok {
for reflectType.Kind() == reflect.Ptr {
reflectType = reflectType.Elem()
}
if reflectType.Kind() == reflect.Struct {
return &Type{
Type: reflectType,
}, nil
}
}
var (
reflectValue reflect.Value
reflectKind reflect.Kind