pp_projekt/dbConnector.go
2019-01-12 22:07:47 +01:00

30 lines
426 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() {
var err error
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!")
}