Skip to content

Commit

Permalink
client/pool - allow to check a connection to DB inside pool initializ…
Browse files Browse the repository at this point in the history
…ation - add getDefaultPoolOptions
  • Loading branch information
atercattus committed Jan 22, 2024
1 parent 8a62053 commit 77e0244
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions client/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client

import (
"context"
"log"
"math"
"math/rand"
"sync"
Expand Down Expand Up @@ -85,12 +86,13 @@ func NewPoolWithOptions(
dbName string,
options ...PoolOption,
) (*Pool, error) {
po := poolOptions{
addr: addr,
user: user,
password: password,
dbName: dbName,
}
po := getDefaultPoolOptions()

po.addr = addr
po.user = user
po.password = password
po.dbName = dbName

for _, o := range options {
o(&po)
}
Expand Down Expand Up @@ -598,3 +600,13 @@ func (pool *Pool) checkConnection(ctx context.Context) error {
return ctx.Err()
}
}

// getDefaultPoolOptions returns pool config for low load services
func getDefaultPoolOptions() poolOptions {
return poolOptions{
logFunc: log.Printf,
minAlive: 1,
maxAlive: 10,
maxIdle: 2,
}
}

0 comments on commit 77e0244

Please sign in to comment.