-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
gstructs.go
62 lines (49 loc) · 2.2 KB
/
gstructs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
// Package gstructs provides functions for struct information retrieving.
package gstructs
import (
"reflect"
)
// Type wraps reflect.Type for additional features.
type Type struct {
reflect.Type
}
// Field contains information of a struct field .
type Field struct {
Value reflect.Value // The underlying value of the field.
Field reflect.StructField // The underlying field of the field.
// Retrieved tag name. It depends TagValue.
TagName string
// Retrieved tag value.
// There might be more than one tags in the field, but only one can be retrieved according to calling function rules.
TagValue string
}
// FieldsInput is the input parameter struct type for function Fields.
type FieldsInput struct {
// Pointer should be type of struct/*struct.
Pointer interface{}
// RecursiveOption specifies the way retrieving the fields recursively if the attribute
// is an embedded struct. It is RecursiveOptionNone in default.
RecursiveOption RecursiveOption
}
// FieldMapInput is the input parameter struct type for function FieldMap.
type FieldMapInput struct {
// Pointer should be type of struct/*struct.
Pointer interface{}
// 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.
PriorityTagArray []string
// RecursiveOption specifies the way retrieving the fields recursively if the attribute
// is an embedded struct. It is RecursiveOptionNone in default.
RecursiveOption RecursiveOption
}
type RecursiveOption int
const (
RecursiveOptionNone RecursiveOption = 0 // No recursively retrieving fields as map if the field is an embedded struct.
RecursiveOptionEmbedded RecursiveOption = 1 // Recursively retrieving fields as map if the field is an embedded struct.
RecursiveOptionEmbeddedNoTag RecursiveOption = 2 // Recursively retrieving fields as map if the field is an embedded struct and the field has no tag.
)