Documentation
¶
Index ¶
- Constants
- type Config
- func (c *Config) Build() Config
- func (c Config) GetConnStr() string
- func (c *Config) WithDb(name string) *Config
- func (c *Config) WithHealthCheckPeriod(duration time.Duration) *Config
- func (c *Config) WithHost(hostname string) *Config
- func (c *Config) WithMaxConnIdleTime(duration time.Duration) *Config
- func (c *Config) WithMaxConnLifeTime(duration time.Duration) *Config
- func (c *Config) WithMaxConnLifeTimeJitter(duration time.Duration) *Config
- func (c *Config) WithMaxConns(count int32) *Config
- func (c *Config) WithMinConns(count int32) *Config
- func (c *Config) WithPass(pass string) *Config
- func (c *Config) WithPort(port int) *Config
- func (c *Config) WithSslMode(mode SSLMode) *Config
- func (c *Config) WithUser(name string) *Config
- type PgClient
- type SSLMode
Constants ¶
View Source
const ( SSLDisable SSLMode = "disable" SSLRequire SSLMode = "require" SSLVerify SSLMode = "verify-full" DEFAULT_MAX_CONNS = 1 DEFAULT_MIN_CONNS = 1 DEFAULT_MAX_IDLE_TIME = 30 * time.Minute DEFAULT_MAX_LIFE_TIME = 60 * time.Minute DEFAULT_MAX_LIFE_TIME_JITTER = 0 DEFAULT_HEALTH_CHECK = 1 * time.Minute )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
User string
Pass string
Host string
Port int
DbName string
SslMode SSLMode
// MaxConnCount is the maximum size of the pool.
MaxConnCount int32
// MinConnCount is the minimum size of the pool.
// After connection closes, the pool might dip below
// MinConns. A low number of MinConns might mean the
// pool is empty after MaxConnLifetime until the
// health check has a chance to create new connections.
MinConnCount int32
MaxConnIdleTime time.Duration
// MaxConnLifeTime is the duration since creation after which a connection will be automatically closed.
MaxConnLifeTime time.Duration
MaxConnLifeTimeJitter time.Duration
// HealthCheckPeriod is the duration between checks of the health of idle connections.
HealthCheckPeriod time.Duration
}
func DefatulConf ¶
func DefatulConf() *Config
func (Config) GetConnStr ¶
GetConnStr parses the Config data to create a connection string
func (*Config) WithHealthCheckPeriod ¶
func (*Config) WithMaxConnIdleTime ¶
func (*Config) WithMaxConnLifeTime ¶
func (*Config) WithMaxConnLifeTimeJitter ¶
func (*Config) WithMaxConns ¶
func (*Config) WithMinConns ¶
func (*Config) WithSslMode ¶
type PgClient ¶
type PgClient struct {
// contains filtered or unexported fields
}
func (*PgClient) Close ¶
func (d *PgClient) Close()
Close closes all connections in the pool and rejects future Acquire calls. Blocks until all connections are returned to pool and closed.
func (*PgClient) Connect ¶
Connect creates a postgres connection pool with specified Config and assigns it to PgClient's driver Use PgClient.Ping to make sure postgres connection is alive.
Click to show internal directories.
Click to hide internal directories.