database/sql and Drivers
DB setup, QueryRow, Scan, and connection pools
database/sql overview
database/sql is Go's standard database abstraction layer. It manages a connection pool and works with any database via a driver plugin.
Registering a driver
Import the driver package for its side effects (driver registration). Then open a connection:
import _ "github.com/lib/pq" // PostgreSQL driver
db, err := sql.Open("postgres", "postgres://user:pass@localhost/mydb?sslmode=disable")
if err != nil { log.Fatal(err) }
defer db.Close()