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



沒有留言:

張貼留言

別名演算法 Alias Method

 題目 每個伺服器支援不同的 TPM (transaction per minute) 當 request 來的時候, 系統需要馬上根據 TPM 的能力隨機找到一個適合的 server. 雖然稱為 "隨機", 但還是需要有 TPM 作為權重. 解法 別名演算法...