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) *PkgNameParameters & 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. |
| imported | *Package | Input 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())}