database.go 586 B

12345678910111213141516171819202122232425
  1. // Copyright 2018 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package database
  5. import (
  6. "database/sql"
  7. // Postgresql driver import
  8. _ "github.com/lib/pq"
  9. )
  10. // NewConnectionPool configures the database connection pool.
  11. func NewConnectionPool(dsn string, minConnections, maxConnections int) (*sql.DB, error) {
  12. db, err := sql.Open("postgres", dsn)
  13. if err != nil {
  14. return nil, err
  15. }
  16. db.SetMaxOpenConns(maxConnections)
  17. db.SetMaxIdleConns(minConnections)
  18. return db, nil
  19. }