Standard library / go/types

go/types.ObjectString()

Formats an object declaration using the supplied package qualifier. Expected stdout: 'var x int\n'.

Formal Syntax & Structure

go syntaxgo
func ObjectString(obj Object, qf Qualifier) string

Parameters & Attributes

NameTypeDescription
objObjectObject associated with the type or scope.
qfQualifierOptional package-name qualifier for formatted type names.

Return Value

string

Formats an object declaration using the supplied package qualifier.

Working Example

Example Snippetgo
package main
import (  "fmt"  "go/types")
func main() {  v := types.NewVar(0, nil, "x", types.Typ[types.Int])  fmt.Println(types.ObjectString(v, nil))}
Go Reference