make db pool size configurable

This commit is contained in:
Dawid Wysokiński 2020-12-22 18:20:03 +01:00
parent 49b6c8a82e
commit 1b8fce636d
1 changed files with 13 additions and 0 deletions

13
main.go
View File

@ -71,6 +71,7 @@ func main() {
Password: os.Getenv("DB_PASSWORD"),
Database: os.Getenv("DB_NAME"),
Addr: os.Getenv("DB_HOST") + ":" + os.Getenv("DB_PORT"),
PoolSize: mustParseEnvToInt("DB_POOL_SIZE"),
})
defer func() {
if err := db.Close(); err != nil {
@ -193,3 +194,15 @@ func main() {
}
log.Println("Server exiting")
}
func mustParseEnvToInt(key string) int {
str := os.Getenv(key)
if str == "" {
return 0
}
i, err := strconv.Atoi(str)
if err != nil {
return 0
}
return i
}