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) *Var

Parameters & Attributes

NameTypeDescription
postoken.PosSource position in the associated file set.
pkg*PackagePackage containing the symbol; nil for package-independent objects.
namestringName of the symbol or package.
typTypeType associated with the object or value.
embeddedboolInput 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())}
Go Reference