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