Tutorial by Examples

Package can have init methods which are run only once before main. package usefull func init() { // init code } If you just want to run the package initialization without referencing anything from it use the following import expression. import _ "usefull"
A common way to download Go dependencies is by using the go get <package> command, which will save the package into the global/shared $GOPATH/src directory. This means that a single version of each package will be linked into each project that includes it as a dependency. This also means that...
It is perfectly fine to use a package name other than the folder name. If we do so, we still have to import the package based on the directory structure, but after the import we have to refer to it by the name we used in the package clause. For example, if you have a folder $GOPATH/src/mypck, and i...
You can import a single package with the statement: import "path/to/package" or group multiple imports together: import ( "path/to/package1" "path/to/package2" ) This will look in the corresponding import paths inside of the $GOPATH for .go files and ...

Page 1 of 1