Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DatabaseConnection ¶
type DatabaseConnection interface {
// Type 返回数据库类型
Type() DatabaseType
// Connect 建立连接
Connect() error
// Close 关闭连接
Close() error
// HealthCheck 健康检查
HealthCheck(ctx context.Context) error
// GetClient 获取原始客户端
GetClient() interface{}
}
DatabaseConnection 数据库连接接口
type DatabaseType ¶
type DatabaseType string
DatabaseType 数据库类型
const ( MySQL DatabaseType = "mysql" Redis DatabaseType = "redis" MongoDB DatabaseType = "mongodb" )
type MongoConfig ¶ added in v0.3.2
type MongoConfig struct {
URL string `json:"url" mapstructure:"url"`
UseSSL bool `json:"use-ssl" mapstructure:"use-ssl"`
SSLInsecureSkipVerify bool `json:"ssl-insecure-skip-verify" mapstructure:"ssl-insecure-skip-verify"`
SSLAllowInvalidHostnames bool `json:"ssl-allow-invalid-hostnames" mapstructure:"ssl-allow-invalid-hostnames"`
SSLCAFile string `json:"ssl-ca-file" mapstructure:"ssl-ca-file"`
SSLPEMKeyfile string `json:"ssl-pem-keyfile" mapstructure:"ssl-pem-keyfile"`
}
MongoConfig MongoDB 数据库配置
type MongoDBConnection ¶ added in v0.3.2
type MongoDBConnection struct {
// contains filtered or unexported fields
}
MongoDBConnection MongoDB 连接实现
func NewMongoDBConnection ¶ added in v0.3.2
func NewMongoDBConnection(config *MongoConfig) *MongoDBConnection
NewMongoDBConnection 创建 MongoDB 连接
func (*MongoDBConnection) Close ¶ added in v0.3.2
func (m *MongoDBConnection) Close() error
Close 关闭 MongoDB 连接
func (*MongoDBConnection) Connect ¶ added in v0.3.2
func (m *MongoDBConnection) Connect() error
Connect 连接 MongoDB 数据库
func (*MongoDBConnection) GetClient ¶ added in v0.3.2
func (m *MongoDBConnection) GetClient() interface{}
GetClient 获取 MongoDB 客户端
func (*MongoDBConnection) HealthCheck ¶ added in v0.3.2
func (m *MongoDBConnection) HealthCheck(ctx context.Context) error
HealthCheck 检查 MongoDB 连接是否健康
func (*MongoDBConnection) Type ¶ added in v0.3.2
func (m *MongoDBConnection) Type() DatabaseType
Type 返回数据库类型
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.