30 lines
458 B
Go
30 lines
458 B
Go
package main
|
|
|
|
import (
|
|
// External
|
|
"github.com/jmoiron/sqlx"
|
|
_ "github.com/lib/pq"
|
|
|
|
// Standard
|
|
"fmt"
|
|
)
|
|
|
|
var (
|
|
db *sqlx.DB
|
|
)
|
|
|
|
func initDB(host string, port int, dbName, username, password string) (err error) { // {{{
|
|
dbConn := fmt.Sprintf(
|
|
"host=%s port=%d user=%s password=%s dbname=%s sslmode=disable",
|
|
host,
|
|
port,
|
|
username,
|
|
password,
|
|
dbName,
|
|
)
|
|
if db, err = sqlx.Connect("postgres", dbConn); err != nil {
|
|
return
|
|
}
|
|
|
|
return
|
|
} // }}}
|