例如,有没有一种方法可以替代:
import "fmt" func main() { fmt.Println("Hello, world") }
有了这个:
import "fmt" func main() { Println("Hello, world") }
The Go Programming Language Specification Import declarations 如果出现显式句点(.)而不是名称,则所有包的 在该包的包块中声明的导出标识符将 在导入源文件的文件块中声明,并且必须 无限定符访问。
The Go Programming Language Specification
Import declarations
如果出现显式句点(.)而不是名称,则所有包的 在该包的包块中声明的导出标识符将 在导入源文件的文件块中声明,并且必须 无限定符访问。
package main import . "fmt" func main() { Println("Hello, world") }
游乐场: https://play.golang.org/p/xl7DIxxMlU5
输出:
Hello, world