- Go Machine Learning Projects
- Xuanyi Chew
- 245字
- 2021-06-10 18:46:33
Packages and imports
Finally, we come to the concept of packages and imports. For the majority of the book, the projects described live in something called a main package. The main package is a special package. Compiling a main package will yield an executable file that you can run.
Having said that, it's also often a good idea to organize your code into multiple packages. Packages are a form of abstraction barrier that we discussed previously with regards to variables and names. Exported names are accessible from outside the package. Exported fields of structs are also accessible from outside the package.
To import a package, you need to invoke an import statement at the top of the file:
package main
import "PACKAGE LOCATION"
Throughout this book I will be explicit in what to import, especially with external libraries that cannot be found in the Go standard library. We will be using a number of those, so I will be explicit.
Go enforces code hygiene. If you import a package and don't use it, your program will not compile. Again, this is a good thing as it makes it less likely to confuse yourself at a later point in time. I personally use a tool called goimports to manage my imports for me. Upon saving my file, goimports adds the import statements for me, and removes any unused packages from my import statements.
To install goimports, run the following command in your Terminal:
go get golang.org/x/tools/cmd/goimports
- 高效能辦公必修課:Word圖文處理
- Word 2000、Excel 2000、PowerPoint 2000上機(jī)指導(dǎo)與練習(xí)
- 并行數(shù)據(jù)挖掘及性能優(yōu)化:關(guān)聯(lián)規(guī)則與數(shù)據(jù)相關(guān)性分析
- 最后一個人類
- RPA(機(jī)器人流程自動化)快速入門:基于Blue Prism
- Ruby on Rails敏捷開發(fā)最佳實踐
- Enterprise PowerShell Scripting Bootcamp
- 電腦上網(wǎng)輕松入門
- 實用網(wǎng)絡(luò)流量分析技術(shù)
- 網(wǎng)絡(luò)脆弱性掃描產(chǎn)品原理及應(yīng)用
- INSTANT Adobe Story Starter
- 三菱FX/Q系列PLC工程實例詳解
- Web編程基礎(chǔ)
- 生成對抗網(wǎng)絡(luò)項目實戰(zhàn)
- 計算機(jī)硬件技術(shù)基礎(chǔ)(第2版)