我使用了ConnecConfig函数来创建一个池。然而,我对用下面的代码构建它并不满意。
编译器消息: ConnectConfig 未由包 pgxpool 声明
package main
import (
"context"
"fmt"
"time"
"github.com/gin-gonic/gin"
"github.com/jackc/pgx/v5/pgxpool"
)
...
func NewConPool() pgxpool.Config {
c, err := pgxpool.ParseConfig(config.GetString("pgx.constr"))
if err != nil {
panic(fmt.Errorf("database configuration could not be read, %w", err))
}
c.MaxConns = config.GetInt32("pgxpool.maxConns")
c.MinConns = config.GetInt32("pgxpool.minConns")
c.MaxConnLifetime = time.Duration(int32(time.Second) * config.GetInt32("pgxpool.maxConnLifetimeSec"))
c.MaxConnIdleTime = time.Duration(int32(time.Second) * config.GetInt32("pgxpool.maxConnIdleTimeSec"))
c.HealthCheckPeriod = time.Duration(int32(time.Second) * config.GetInt32("pgxpool.healthCheckPeriodSec"))
c.ConnConfig.ConnectTimeout = time.Duration(int32(time.Second) * config.GetInt32("pgxpool.connectTimeoutSec"))
pool, err := pgxpool.ConnectConfig(context.Background(), c) //<-this line
return *pool
}```
尝试从
"github.com/jackc/pgx/v5/pgxpool"
更改为
_“github.com/jackc/pgx/v5/pgxpool”
并且 pgx v5 中不存在 ConnectConfig,请使用 v4 或其他方法