September 2017
Intermediate to advanced
466 pages
9h 33m
English
Sometimes packages are available on the internet and you would prefer to use them by specifying their internet address. One such example is the Go MySQL driver that can be found at github.com/go-sql-driver/mysql.
Look at the following Go code, which is saved as useMySQL.go:
package main
import (
"fmt"
_ "github.com/go-sql-driver/mysql")
func main() {
fmt.Println("Using the MySQL Go driver!")
}
The use of _ as the package identifier will make the compiler ignore the fact that the package is not being used: the only sensible reason for bypassing the compiler is when you have an init function in your unused package that you want to be executed. The other sensible reason is for illustrating a Go concept!
If you try ...
Read now
Unlock full access