Go does not use DSN (Data Source Name) connection strings; it uses standard URL-style connection strings directly in driver-specific functions. Pass your database credentials and host details as a single string argument to sql.Open or the driver's initialization function.
import "database/sql"
import _ "github.com/lib/pq"
connStr := "host=localhost user=myuser password=mypass dbname=mydb sslmode=disable"
db, err := sql.Open("postgres", connStr)
if err != nil {
panic(err)
}
defer db.Close()
For MySQL, the format is user:password@tcp(host:port)/dbname.