Initial commit
This commit is contained in:
commit
dc8a638814
4 changed files with 209 additions and 0 deletions
31
db.go
Normal file
31
db.go
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
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
|
||||
} // }}}
|
||||
Loading…
Add table
Add a link
Reference in a new issue