Standard library / go/types
go/types.Package.SetName()
Sets the package name, independently of its import path. Expected stdout: 'new example.invalid/p\n'.
Formal Syntax & Structure
go syntaxgo
func (pkg *Package) SetName(name string)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| name | string | Name of the symbol or package. |
Working Example
Example Snippetgo
package main
import ( "fmt" "go/types")
func main() { p := types.NewPackage("example.invalid/p", "old") p.SetName("new") fmt.Println(p.Name(), p.Path())}