# Field Field is abstract struct field for provide several high level functions
## Source: - [https://github.com/duke-git/lancet/blob/main/structs/field.go](https://github.com/duke-git/lancet/blob/main/structs/field.go) ## Usage: ```go import ( "github.com/duke-git/lancet/v2/structs" ) ``` ## Index: - [Tag](#Tag) - [Name](#Name) - [Value](#Value) - [Kind](#Kind) - [IsEmbedded](#IsEmbedded) - [IsExported](#IsExported) - [IsZero](#IsZero) - [IsSlice](#IsSlice) > Noteļ¼Since `Field` inherits from `Struct`, it also has all the methods of 'Struct', as follows: - [ToMap](https://github.com/duke-git/lancet/blob/main/docs/structs/struct.md#ToMap) - [Fields](https://github.com/duke-git/lancet/blob/main/docs/structs/struct.md#Fields) - [Field](https://github.com/duke-git/lancet/blob/main/docs/structs/struct.md#Field) - [IsStruct](https://github.com/duke-git/lancet/blob/main/docs/structs/struct.md#IsStruct) ## Documentation: ### TagGet a `Tag` of the `Field`, `Tag` is a abstract struct field tag
Signature: ```go func (f *Field) Tag() *Tag ``` Example: ```go package main import ( "fmt" "github.com/duke-git/lancet/v2/structs" ) func main() { type Parent struct { Name string `json:"name,omitempty"` } p1 := &Parent{"111"} s := structs.New(p1) n, _ := s.Field("Name") tag := n.Tag() fmt.Println(tag.Name) // Output: // name } ``` ### ValueGet the `Field` underlying value
Signature: ```go func (f *Field) Value() any ``` Example: ```go package main import ( "fmt" "github.com/duke-git/lancet/v2/structs" ) func main() { type Parent struct { Name string `json:"name,omitempty"` } p1 := &Parent{"111"} s := structs.New(p1) n, _ := s.Field("Name") fmt.Println(n.Value()) // Output: // 111 } ``` ### IsEmbeddedCheck if the field is an embedded field
Signature: ```go func (f *Field) IsEmbedded() bool ``` Example: ```go package main import ( "fmt" "github.com/duke-git/lancet/v2/structs" ) func main() { type Parent struct { Name string } type Child struct { Parent Age int } c1 := &Child{} c1.Name = "111" c1.Age = 11 s := structs.New(c1) n, _ := s.Field("Name") a, _ := s.Field("Age") fmt.Println(n.IsEmbedded()) fmt.Println(a.IsEmbedded()) // Output: // true // false } ``` ### IsExportedCheck if the field is exported
Signature: ```go func (f *Field) IsExported() bool ``` Example: ```go package main import ( "fmt" "github.com/duke-git/lancet/v2/structs" ) func main() { type Parent struct { Name string age int } p1 := &Parent{Name: "11", age: 11} s := structs.New(p1) n, _ := s.Field("Name") a, _ := s.Field("age") fmt.Println(n.IsExported()) fmt.Println(a.IsExported()) // Output: // true // false } ``` ### IsZeroCheck if the field is zero value
Signature: ```go func (f *Field) IsZero() bool ``` Example: ```go package main import ( "fmt" "github.com/duke-git/lancet/v2/structs" ) func main() { type Parent struct { Name string Age int } p1 := &Parent{Age: 11} s := structs.New(p1) n, _ := s.Field("Name") a, _ := s.Field("Age") fmt.Println(n.IsZero()) fmt.Println(a.IsZero()) // Output: // true // false } ``` ### NameGet the field name
Signature: ```go func (f *Field) Name() string ``` Example: ```go package main import ( "fmt" "github.com/duke-git/lancet/v2/structs" ) func main() { type Parent struct { Name string Age int } p1 := &Parent{Age: 11} s := structs.New(p1) n, _ := s.Field("Name") a, _ := s.Field("Age") fmt.Println(n.Name()) fmt.Println(a.Name()) // Output: // Name // Age } ``` ### KindGet the field's kind
Signature: ```go func (f *Field) Kind() reflect.Kind ``` Example: ```go package main import ( "fmt" "github.com/duke-git/lancet/v2/structs" ) func main() { type Parent struct { Name string Age int } p1 := &Parent{Age: 11} s := structs.New(p1) n, _ := s.Field("Name") a, _ := s.Field("Age") fmt.Println(n.Kind()) fmt.Println(a.Kind()) // Output: // string // int } ``` ### IsSliceCheck if the field is a slice
Signature: ```go func (f *Field) IsSlice() bool ``` Example: ```go package main import ( "fmt" "github.com/duke-git/lancet/v2/structs" ) func main() { type Parent struct { Name string arr []int } p1 := &Parent{arr: []int{1, 2, 3}} s := structs.New(p1) a, _ := s.Field("arr") fmt.Println(a.IsSlice()) // Output: // true } ```