Standard library / go/types

go/types.Initializer

Describes a package-level initialization assignment. Lhs contains the variables and Rhs is the initializing expression. Expected stdout: 'X 42\n'.

Formal Syntax & Structure

go syntaxgo
type Initializer struct {  Lhs []*Var  Rhs ast.Expr}

Working Example

Example Snippetgo
package main
import (  "fmt"  "go/parser"  "go/types")
func check(e error) {  if e != nil {    panic(e)  }}
func main() {  v := types.NewVar(0, nil, "X", types.Typ[types.Int])  x, e := parser.ParseExpr("42")  check(e)  i := types.Initializer{Lhs: []*types.Var{v}, Rhs: x}  fmt.Println(i.Lhs[0].Name(), types.ExprString(i.Rhs))}
Go Reference