35 lines
590 B
Go
35 lines
590 B
Go
package storage
|
|
|
|
import (
|
|
"database/sql"
|
|
"fmt"
|
|
)
|
|
|
|
const (
|
|
host = "localhost"
|
|
port = 5432
|
|
user = "postgres"
|
|
password = "@#postgres-passWoRD#@"
|
|
dbname = "aicratest"
|
|
)
|
|
|
|
var psqlInfo = fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable", host, port, user, password, dbname)
|
|
|
|
// New returns new postgres connection.
|
|
func New() (*sql.DB, error) {
|
|
|
|
conn, err := sql.Open("postgres", psqlInfo)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer conn.Close()
|
|
|
|
// actually connect
|
|
err = conn.Ping()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return conn, nil
|
|
}
|