33 lines
617 B
Go
33 lines
617 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"database/sql"
|
||
|
"fmt"
|
||
|
)
|
||
|
|
||
|
var db *sql.DB
|
||
|
|
||
|
const (
|
||
|
dbhost = "DBHOST"
|
||
|
dbport = "5432"
|
||
|
dbuser = "postgres"
|
||
|
dbpass = "admin"
|
||
|
dbname = "mydb"
|
||
|
)
|
||
|
|
||
|
func initDb() {
|
||
|
//config := dbConfig()
|
||
|
var err error
|
||
|
//psqlInfo := fmt.Sprintf("host=localhost port=%s user=%s password=%s dbname=%s sslmode=disable",
|
||
|
// config[dbport], config[dbuser], config[dbpass], config[dbname])
|
||
|
|
||
|
db, err = sql.Open("postgres", "port=5432 password=admin user=postgres dbname=mydb sslmode=disable")
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
err = db.Ping()
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
fmt.Println("Successfullu connected!")
|
||
|
}
|