Import everything from a package

后端 未结 1 859
走了就别回头了
走了就别回头了 2021-01-03 06:01

I\'m wondering if there is any way to import the full contents of a package so that I don\'t have to prefix calls to things in the package with a package name?

For e

1条回答
  •  囚心锁ツ
    2021-01-03 06:35

    The Go Programming Language Specification

    Import declarations

    If an explicit period (.) appears instead of a name, all the package's exported identifiers declared in that package's package block will be declared in the importing source file's file block and must be accessed without a qualifier.


    For example,

    package main
    
    import . "fmt"
    
    func main() {
        Println("Hello, world")
    }
    

    Playground: https://play.golang.org/p/xl7DIxxMlU5

    Output:

    Hello, world
    

    0 讨论(0)
提交回复
热议问题