Standard library / go/types
go/types.NewParam()
Creates a variable representing a function parameter. Expected stdout: 'x int\n'.
Formal Syntax & Structure
go syntaxgo
func NewParam(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 representing a function parameter.
Working Example
Example Snippetgo
package main
import ( "fmt" "go/types")
func main() { p := types.NewParam(0, nil, "x", types.Typ[types.Int]); fmt.Println(p.Name(), p.Type()) }