Standard library / go/types
go/types.NewField()
Creates a struct field variable; embedded indicates an embedded field. Expected stdout: 'X true false\n'.
Formal Syntax & Structure
go syntaxgo
func NewField(pos token.Pos, pkg *Package, name string, typ Type, embedded bool) *VarParameters & Attributes
| Name | Type | Description |
|---|---|---|
| pos | token.Pos | Source position in the associated file set. |
| pkg | *Package | Package containing the symbol; nil for package-independent objects. |
| name | string | Name of the symbol or package. |
| typ | Type | Type associated with the object or value. |
| embedded | bool | Input to the operation as described above. |
Return Value
*Var
Creates a struct field variable; embedded indicates an embedded field.
Working Example
Example Snippetgo
package main
import ( "fmt" "go/types")
func main() { v := types.NewField(0, nil, "X", types.Typ[types.Int], false) fmt.Println(v.Name(), v.IsField(), v.Embedded())}