Go - Package import and initialization


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



沒有留言:

張貼留言

Lessons Learned While Using Claude Code Skills

Recently, I started experimenting with Claude Code Skills . I first saw this YouTube video: https://www.youtube.com/watch?v=CEvIs9y1uog ...