Note Takes
- When naming your packages and their directories you should use short, concise, lowercase names.
- The main package in Go is intended to be compiled into a binary executable, when the main package is encountered by the compiler, it must also find a function called main();
- the Go documentation uses the term command frequently to refer to an executable program like a command line application. contrary to packages which are importable semantic unit of functionality.
- The
import statement tells the compiler where to look on disk to find the package you want to import
- for the standard library usually are located on those paths:
/usr/local/go/src/pkg/net/http
/home/myproject/src/net/http
/home/mylibraries/src/net/http
- There’s another type of import which the remote import, this kind of importing fetches the packages from a version control system via URL:
import "github.com/spf13/viper"
- when you’re encountring the case of importing 2 different packages that have the same name, to avoid the name confusion, Go provides an utility called the named imports that enable you to give specific names to imported packages using the following syntax
01 package main
02
03 import (
04 "fmt"
05 myfmt "mylib/fmt"
06 )
07
08 func main() {
09 fmt.Println("Standard Library")
10 myfmt.Println("mylib/fmt")
11 }