mirror of
https://github.com/rjNemo/go-wiki
synced 2026-06-06 02:36:40 +00:00
27 lines
449 B
Go
27 lines
449 B
Go
package data
|
|
|
|
import (
|
|
"database/sql"
|
|
"log"
|
|
|
|
_ "github.com/lib/pq"
|
|
"github.com/rjNemo/go-wiki/settings"
|
|
)
|
|
|
|
// Connect read the connection parameters to establish a connection to the
|
|
// database.
|
|
func Connect() {
|
|
connStr := settings.ConnStr
|
|
db, err := sql.Open("postgres", connStr)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
defer db.Close()
|
|
|
|
err = db.Ping()
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
log.Println("Database successfully connected!")
|
|
}
|