db

package
v0.0.0-...-45423dd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 24, 2021 License: Apache-2.0 Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	DbConfig            *DbConfig
	SsmServiceConfig    *ssm.SsmAccount
	WatchChangeInterval time.Duration
}

func (*Config) BuildConnStr

func (c *Config) BuildConnStr() (string, error)

type ConnCache

type ConnCache struct {
	ConnStr string // 缓存的当前正在使用的连接信息
	Conn    *sql.DB
}

type DbConfig

type DbConfig struct {
	MaxOpenConns        int
	MaxIdleConns        int
	IdleTimeoutSeconds  int
	ReadTimeoutSeconds  int
	WriteTimeoutSeconds int
	SecretName          string
	IpAddress           string
	Port                uint64
	DbName              string
	ParamStr            string // 例如:charset=utf8&loc=Local
}

type DynamicSecretRotationDb

type DynamicSecretRotationDb struct {
	// contains filtered or unexported fields
}

func (*DynamicSecretRotationDb) GetConn

func (d *DynamicSecretRotationDb) GetConn() *sql.DB

* 调用方每次访问db时,需通过调用本方法获取db连接。 注意:请不要在调用端缓存获取到的 *sql.DB, 以便确保在凭据发生轮换后,能及时的获得到最新的用户名和密码,防止由于用户名密码过期,而造成数据库连接失败!

func (*DynamicSecretRotationDb) Init

func (d *DynamicSecretRotationDb) Init(config *Config) error

* 在服务初始化的时候,可调用本方法来完成数据库连接的初始化。 本方法根据提供的凭据相关的信息(服务账号,凭据名),获得真实的数据库用户名和密码信息,然后生成数据库连接

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL