Standard library / go/types

go/types.NewPkgName()

Creates a local import-name binding pointing to an imported package. Expected stdout: 'alias example.invalid/dep\n'.

Formal Syntax & Structure

go syntaxgo
func NewPkgName(pos token.Pos, pkg *Package, name string, imported *Package) *PkgName

Parameters & Attributes

NameTypeDescription
postoken.PosSource position in the associated file set.
pkg*PackagePackage containing the symbol; nil for package-independent objects.
namestringName of the symbol or package.
imported*PackageInput to the operation as described above.

Return Value

*PkgName

Creates a local import-name binding pointing to an imported package.

Working Example

Example Snippetgo
package main
import (  "fmt"  "go/types")
func main() {  p := types.NewPackage("example.invalid/dep", "dep")  o := types.NewPkgName(0, nil, "alias", p)  fmt.Println(o.Name(), o.Imported().Path())}
Go Reference