Standard library / go/types

go/types.Initializer.String()

Formats an initialization assignment for diagnostics. Expected stdout: 'X = 42\n'.

Formal Syntax & Structure

go syntaxgo
func (init *Initializer) String() string

Return Value

string

Formats an initialization assignment for diagnostics.

Working Example

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