You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
weather/internal/postgres/database.go

32 lines
642 B

package postgres
import (
"database/sql"
"fmt"
"log"
"github.com/dustinpianalto/weather"
_ "github.com/lib/pq"
)
var (
EventService weather.AmbientService
)
func ConnectDatabase(dbConnString string) {
db, err := sql.Open("postgres", dbConnString)
if err != nil {
panic(fmt.Sprintf("Can't connect to the database. %v", err))
}
db.SetMaxOpenConns(75) // The RDS instance has a max of 75 open connections
db.SetMaxIdleConns(5)
db.SetConnMaxLifetime(300)
log.Println("Database Connected")
initServices(db)
log.Println("Postgres Database Initialized")
}
func initServices(db *sql.DB) {
EventService = eventService{db: db}
}