Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DatabaseConnection ¶
type DatabaseConnection interface {
Type() DatabaseType
Connect() error
Close() error
HealthCheck(ctx context.Context) error
GetClient() interface{}
}
DatabaseConnection 数据库连接接口
type DatabaseType ¶
type DatabaseType string
DatabaseType 数据库类型
const ( MySQL DatabaseType = "mysql" Redis DatabaseType = "redis" )
type MySQLConfig ¶
type MySQLConfig struct {
Host string `json:"host" mapstructure:"host"`
Username string `json:"username" mapstructure:"username"`
Password string `json:"password" mapstructure:"password"`
Database string `json:"database" mapstructure:"database"`
MaxIdleConnections int `json:"max-idle-connections" mapstructure:"max-idle-connections"`
MaxOpenConnections int `json:"max-open-connections" mapstructure:"max-open-connections"`
MaxConnectionLifeTime time.Duration `json:"max-connection-life-time" mapstructure:"max-connection-life-time"`
LogLevel int `json:"log-level" mapstructure:"log-level"`
Logger logger.Interface
}
MySQLConfig MySQL 数据库配置
type MySQLConnection ¶
type MySQLConnection struct {
// contains filtered or unexported fields
}
MySQLConnection MySQL 连接实现
func NewMySQLConnection ¶
func NewMySQLConnection(config *MySQLConfig) *MySQLConnection
NewMySQLConnection 创建 MySQL 连接
func (*MySQLConnection) GetClient ¶
func (m *MySQLConnection) GetClient() interface{}
GetClient 获取 MySQL 客户端
func (*MySQLConnection) HealthCheck ¶
func (m *MySQLConnection) HealthCheck(ctx context.Context) error
HealthCheck 检查 MySQL 连接是否健康
type RedisConfig ¶
type RedisConfig struct {
Host string `json:"host" mapstructure:"host"`
Port int `json:"port" mapstructure:"port"`
Addrs []string `json:"addrs" mapstructure:"addrs"`
Password string `json:"password" mapstructure:"password"`
Database int `json:"database" mapstructure:"database"`
MaxIdle int `json:"max-idle" mapstructure:"max-idle"`
MaxActive int `json:"max-active" mapstructure:"max-active"`
Timeout int `json:"timeout" mapstructure:"timeout"`
EnableCluster bool `json:"enable-cluster" mapstructure:"enable-cluster"`
UseSSL bool `json:"use-ssl" mapstructure:"use-ssl"`
SSLInsecureSkipVerify bool `json:"ssl-insecure-skip-verify" mapstructure:"ssl-insecure-skip-verify"`
}
RedisConfig Redis 数据库配置
type RedisConnection ¶
type RedisConnection struct {
// contains filtered or unexported fields
}
RedisConnection Redis 连接实现
func NewRedisConnection ¶
func NewRedisConnection(config *RedisConfig) *RedisConnection
NewRedisConnection 创建 Redis 连接
func (*RedisConnection) GetClient ¶
func (r *RedisConnection) GetClient() interface{}
GetClient 获取 Redis 客户端
func (*RedisConnection) HealthCheck ¶
func (r *RedisConnection) HealthCheck(ctx context.Context) error
HealthCheck 检查 Redis 连接是否健康
Click to show internal directories.
Click to hide internal directories.