Standard library / go/types
go/types.NewVar()
Creates a variable object, not runtime storage. Expected stdout: 'count int false\n'.
Formal Syntax & Structure
go syntaxgo
func NewVar(pos token.Pos, pkg *Package, name string, typ Type) *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. |
Return Value
*Var
Creates a variable object, not runtime storage.
Working Example
Example Snippetgo
package main
import ( "fmt" "go/types")
func main() { v := types.NewVar(0, nil, "count", types.Typ[types.Int]) fmt.Println(v.Name(), v.Type(), v.IsField())}