Skip to content

Commit

Permalink
fix: fix duration configuration bug
Browse files Browse the repository at this point in the history
  • Loading branch information
pinglin committed Jun 13, 2022
1 parent 962823b commit 998eafa
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ database:
pool:
idleconnections: 5
maxconnections: 10
connlifetime: 30 # In minutes
connlifetime: 30m # In minutes, e.g., '60m'
cache:
redis:
redisoptions:
Expand Down
4 changes: 2 additions & 2 deletions internal/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package db
import (
"fmt"
"sync"
"time"

"gorm.io/driver/postgres"
"gorm.io/gorm"
Expand Down Expand Up @@ -48,11 +47,12 @@ func GetConnection() *gorm.DB {
// SetMaxOpenConns sets the maximum number of open connections to the database.
sqlDB.SetMaxOpenConns(databaseConfig.Pool.MaxConnections)
// SetConnMaxLifetime sets the maximum amount of time a connection may be reused.
sqlDB.SetConnMaxLifetime(time.Minute * databaseConfig.Pool.ConnLifeTime)
sqlDB.SetConnMaxLifetime(databaseConfig.Pool.ConnLifeTime)
})
return db
}

// Close closes the db connection
func Close(db *gorm.DB) {
// https://github.com/go-gorm/gorm/issues/3216
//
Expand Down

0 comments on commit 998eafa

Please sign in to comment.