Package Import
  1. Import path: packages are identified by an unique string, called import path
  2. Go lang spec doesn't define what "import path" mean, it's up to the tools to interpret them
  3. Declare import without using it will get panic
Package Initialization
  1. init function can't be called, but can be used to init package.
    1. In this case, only main function is initialized
    2. Declare same function name in the same package, even in different file. Will get panic
    3. When main function call package function, package will be initialized before main function.
    4. The order of package initialization follows files order
    5. This picture proves main is the last package to be initialized



What to read next

Previous / Next
Previous: Go - Package and Files Next: Go - Scope
More like this
Subscribe via RSS: Macro · Tech

Tags:

Updated: