Documentation
¶
Index ¶
- func DB(name string) *gorm.DB
- func DefaultSlaveDB() *gorm.DB
- func GetClickHouse(name string) driver.Conn
- func GetClickHouseGORMDB(name string) *gorm.DB
- func GetDefaultClickHouse() driver.Conn
- func GetDefaultClickHouseGORM() *gorm.DB
- func GetDefaultDB() *gorm.DB
- func GinModeForEnv(env string) string
- func GormLogLevelForEnv(env string) logger.LogLevel
- func SlaveDB(name string) *gorm.DB
- type ClickHouseComponent
- type ClickHouseConfig
- type ClickHouseGORMComponent
- type ClickHouseGORMConfig
- type ClickHouseOption
- func WithClickHouseAddress(address []string) ClickHouseOption
- func WithClickHouseCompression(method clickhouse.CompressionMethod) ClickHouseOption
- func WithClickHouseConnMaxLifetime(connMaxLifetime time.Duration) ClickHouseOption
- func WithClickHouseDSN(dsn string) ClickHouseOption
- func WithClickHouseDatabase(database string) ClickHouseOption
- func WithClickHouseDebug(debug bool) ClickHouseOption
- func WithClickHouseDialTimeout(dialTimeout time.Duration) ClickHouseOption
- func WithClickHouseMaxIdleConns(maxIdleConns int) ClickHouseOption
- func WithClickHouseMaxOpenConns(maxOpenConns int) ClickHouseOption
- func WithClickHousePassword(password string) ClickHouseOption
- func WithClickHouseProtocol(protocol string) ClickHouseOption
- func WithClickHouseReadTimeout(readTimeout time.Duration) ClickHouseOption
- func WithClickHouseUsername(username string) ClickHouseOption
- type GinComponent
- type GinConfig
- type GinOption
- type MySQLComponent
- type MySQLConfig
- type RedisClusterComponent
- type RedisClusterOption
- func WithClusterAddrs(addrs []string) RedisClusterOption
- func WithClusterMaxRetries(maxRetries int) RedisClusterOption
- func WithClusterMaxRetryBackoff(maxRetryBackoff time.Duration) RedisClusterOption
- func WithClusterMinIdleConns(minIdleConns int) RedisClusterOption
- func WithClusterMinRetryBackoff(minRetryBackoff time.Duration) RedisClusterOption
- func WithClusterPassword(password string) RedisClusterOption
- func WithClusterPoolSize(poolSize int) RedisClusterOption
- func WithClusterPoolTimeout(poolTimeout time.Duration) RedisClusterOption
- func WithClusterReadTimeout(readTimeout time.Duration) RedisClusterOption
- func WithClusterRouteRandomly(routeRandomly bool) RedisClusterOption
- func WithClusterTimeout(timeout time.Duration) RedisClusterOption
- func WithClusterWriteTimeout(writeTimeout time.Duration) RedisClusterOption
- type RedisComponent
- type RedisOption
- func WithRedisAddr(addr string) RedisOption
- func WithRedisDB(db int) RedisOption
- func WithRedisMaxRetries(maxRetries int) RedisOption
- func WithRedisMaxRetryBackoff(maxRetryBackoff time.Duration) RedisOption
- func WithRedisMinIdleConns(minIdleConns int) RedisOption
- func WithRedisMinRetryBackoff(minRetryBackoff time.Duration) RedisOption
- func WithRedisPassword(password string) RedisOption
- func WithRedisPoolSize(poolSize int) RedisOption
- func WithRedisPoolTimeout(poolTimeout time.Duration) RedisOption
- func WithRedisReadTimeout(readTimeout time.Duration) RedisOption
- func WithRedisWriteTimeout(writeTimeout time.Duration) RedisOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetClickHouse ¶ added in v1.1.7
获取指定名称的ClickHouse连接
func GetClickHouseGORMDB ¶ added in v1.1.9
GetClickHouseGORMDB 获取指定名称的ClickHouse GORM DB
func GetDefaultClickHouse ¶ added in v1.1.7
获取默认ClickHouse连接
func GetDefaultClickHouseGORM ¶ added in v1.1.9
GetDefaultClickHouseGORM 获取默认ClickHouse GORM DB
func GormLogLevelForEnv ¶
GormLogLevelForEnv 根据环境变量设置Gorm日志级别
Types ¶
type ClickHouseComponent ¶ added in v1.1.7
type ClickHouseComponent struct {
// contains filtered or unexported fields
}
ClickHouseComponent ClickHouse组件
var (
DefaultClickHouse *ClickHouseComponent // 添加默认实例
)
func GetClickHouseComponent ¶ added in v1.1.7
func GetClickHouseComponent(name string) *ClickHouseComponent
获取指定名称的ClickHouse组件
func NewClickHouseComponent ¶ added in v1.1.7
func NewClickHouseComponent(name string, isDefault bool, opts ...ClickHouseOption) *ClickHouseComponent
NewClickHouseComponent 创建ClickHouse组件
func (*ClickHouseComponent) GetConn ¶ added in v1.1.7
func (c *ClickHouseComponent) GetConn() driver.Conn
GetConn 获取ClickHouse连接
type ClickHouseConfig ¶ added in v1.1.7
type ClickHouseConfig struct { Address []string // 地址列表,支持集群 Database string // 数据库名 Username string // 用户名 Password string // 密码 MaxOpenConns int // 最大连接数 MaxIdleConns int // 最大空闲连接数 ConnMaxLifetime time.Duration // 连接最大生命周期 DialTimeout time.Duration // 连接超时时间 ReadTimeout time.Duration // 读取超时时间 Compression *clickhouse.Compression // 压缩方式 Debug bool // 调试 Protocol string // 协议类型:native 或 http DSN string // 直接设置DSN连接字符串 }
ClickHouseConfig ClickHouse配置
type ClickHouseGORMComponent ¶ added in v1.1.9
type ClickHouseGORMComponent struct {
// contains filtered or unexported fields
}
ClickHouseGORMComponent ClickHouse GORM组件
var (
DefaultClickHouseGORM *ClickHouseGORMComponent // 默认实例
)
func GetClickHouseGORMComponent ¶ added in v1.1.9
func GetClickHouseGORMComponent(name string) *ClickHouseGORMComponent
GetClickHouseGORMComponent 获取指定名称的ClickHouse GORM组件
func NewClickHouseGORMComponent ¶ added in v1.1.9
func NewClickHouseGORMComponent(name string, config *ClickHouseGORMConfig, isDefault bool) *ClickHouseGORMComponent
NewClickHouseGORMComponent 创建ClickHouse GORM组件
func (*ClickHouseGORMComponent) DB ¶ added in v1.1.9
func (c *ClickHouseGORMComponent) DB() *gorm.DB
DB 获取GORM DB实例
type ClickHouseGORMConfig ¶ added in v1.1.9
type ClickHouseGORMConfig struct { DSN string // DSN连接字符串 MaxIdleConns int // 最大空闲连接数 MaxOpenConns int // 最大打开连接数 ConnMaxLifetime time.Duration // 连接最大生命周期 LogLevel logger.LogLevel // 日志级别 Prefix string // 表前缀 }
ClickHouseGORMConfig ClickHouse GORM配置
type ClickHouseOption ¶ added in v1.1.7
type ClickHouseOption func(*ClickHouseConfig)
ClickHouseOption 定义ClickHouse选项函数类型
func WithClickHouseAddress ¶ added in v1.1.7
func WithClickHouseAddress(address []string) ClickHouseOption
WithClickHouseAddress 设置ClickHouse地址
func WithClickHouseCompression ¶ added in v1.1.7
func WithClickHouseCompression(method clickhouse.CompressionMethod) ClickHouseOption
WithClickHouseCompression 设置压缩方式
func WithClickHouseConnMaxLifetime ¶ added in v1.1.7
func WithClickHouseConnMaxLifetime(connMaxLifetime time.Duration) ClickHouseOption
WithClickHouseConnMaxLifetime 设置连接最大生命周期
func WithClickHouseDSN ¶ added in v1.1.9
func WithClickHouseDSN(dsn string) ClickHouseOption
WithClickHouseDSN 直接设置DSN连接字符串
func WithClickHouseDatabase ¶ added in v1.1.7
func WithClickHouseDatabase(database string) ClickHouseOption
WithClickHouseDatabase 设置ClickHouse数据库
func WithClickHouseDebug ¶ added in v1.1.7
func WithClickHouseDebug(debug bool) ClickHouseOption
WithClickHouseDebug 设置ClickHouse调试
func WithClickHouseDialTimeout ¶ added in v1.1.7
func WithClickHouseDialTimeout(dialTimeout time.Duration) ClickHouseOption
WithClickHouseDialTimeout 设置连接超时时间
func WithClickHouseMaxIdleConns ¶ added in v1.1.7
func WithClickHouseMaxIdleConns(maxIdleConns int) ClickHouseOption
WithClickHouseMaxIdleConns 设置最大空闲连接数
func WithClickHouseMaxOpenConns ¶ added in v1.1.7
func WithClickHouseMaxOpenConns(maxOpenConns int) ClickHouseOption
WithClickHouseMaxOpenConns 设置最大连接数
func WithClickHousePassword ¶ added in v1.1.7
func WithClickHousePassword(password string) ClickHouseOption
WithClickHousePassword 设置ClickHouse密码
func WithClickHouseProtocol ¶ added in v1.1.8
func WithClickHouseProtocol(protocol string) ClickHouseOption
WithClickHouseProtocol 设置ClickHouse协议
func WithClickHouseReadTimeout ¶ added in v1.1.8
func WithClickHouseReadTimeout(readTimeout time.Duration) ClickHouseOption
WithClickHouseReadTimeout 设置读取超时时间
func WithClickHouseUsername ¶ added in v1.1.7
func WithClickHouseUsername(username string) ClickHouseOption
WithClickHouseUsername 设置ClickHouse用户名
type GinComponent ¶
type GinComponent struct {
// contains filtered or unexported fields
}
GinComponent Gin组件
func NewGinComponent ¶
func NewGinComponent(opts ...GinOption) *GinComponent
NewGinComponent 创建Gin组件
func (*GinComponent) Use ¶ added in v1.0.3
func (g *GinComponent) Use(middleware ...gin.HandlerFunc)
Use 添加全局中间件
type GinOption ¶
type GinOption func(*GinComponent)
GinOption 定义Gin选项函数类型
func WithGinMiddleware ¶ added in v1.0.3
func WithGinMiddleware(middleware ...gin.HandlerFunc) GinOption
WithGinMiddleware 添加全局中间件
func WithGinRouter ¶
WithGinRouter 设置路由注册函数
func WithGinShutdownTimeout ¶
WithGinShutdownTimeout 设置关闭超时时间
type MySQLComponent ¶
type MySQLComponent struct {
// contains filtered or unexported fields
}
MySQLComponent MySQL组件
var (
DefaultDB *MySQLComponent // 添加默认实例
)
func NewMySQLComponent ¶
func NewMySQLComponent(name string, config *MySQLConfig, isDefault bool) *MySQLComponent
NewMySQLComponent 创建MySQL组件
type MySQLConfig ¶
type MySQLConfig struct { MasterDSN string SlavesDSN []string // 修改为切片,支持多个从库 MaxIdleConns int MaxOpenConns int ConnMaxLifetime time.Duration LogLevel logger.LogLevel Prefix string }
MySQLConfig MySQL配置
type RedisClusterComponent ¶
type RedisClusterComponent struct {
// contains filtered or unexported fields
}
RedisClusterComponent Redis集群组件
var GlobalRedisClusterComponent *RedisClusterComponent
全局Redis集群组件
func NewRedisClusterComponent ¶
func NewRedisClusterComponent(opts ...RedisClusterOption) *RedisClusterComponent
NewRedisClusterComponent 创建Redis集群组件
func (*RedisClusterComponent) GetClient ¶
func (r *RedisClusterComponent) GetClient() *redis.ClusterClient
GetClient 获取Redis集群客户端
type RedisClusterOption ¶
type RedisClusterOption func(*RedisClusterComponent)
RedisClusterOption 定义Redis集群选项函数类型
func WithClusterAddrs ¶
func WithClusterAddrs(addrs []string) RedisClusterOption
WithClusterAddrs 设置Redis集群地址
func WithClusterMaxRetries ¶
func WithClusterMaxRetries(maxRetries int) RedisClusterOption
WithClusterMaxRetries 设置集群最大重试次数
func WithClusterMaxRetryBackoff ¶
func WithClusterMaxRetryBackoff(maxRetryBackoff time.Duration) RedisClusterOption
WithClusterMaxRetryBackoff 设置集群最大重试间隔时间
func WithClusterMinIdleConns ¶
func WithClusterMinIdleConns(minIdleConns int) RedisClusterOption
WithClusterMinIdleConns 设置集群最小空闲连接数
func WithClusterMinRetryBackoff ¶
func WithClusterMinRetryBackoff(minRetryBackoff time.Duration) RedisClusterOption
WithClusterMinRetryBackoff 设置集群最小重试间隔时间
func WithClusterPassword ¶
func WithClusterPassword(password string) RedisClusterOption
WithClusterPassword 设置Redis集群密码
func WithClusterPoolSize ¶
func WithClusterPoolSize(poolSize int) RedisClusterOption
WithClusterPoolSize 设置集群连接池大小
func WithClusterPoolTimeout ¶
func WithClusterPoolTimeout(poolTimeout time.Duration) RedisClusterOption
WithClusterPoolTimeout 设置集群连接池超时时间
func WithClusterReadTimeout ¶
func WithClusterReadTimeout(readTimeout time.Duration) RedisClusterOption
WithClusterReadTimeout 设置集群读取超时时间
func WithClusterRouteRandomly ¶
func WithClusterRouteRandomly(routeRandomly bool) RedisClusterOption
WithClusterRouteRandomly 设置集群是否随机路由
func WithClusterTimeout ¶
func WithClusterTimeout(timeout time.Duration) RedisClusterOption
WithClusterTimeout 设置集群连接超时时间
func WithClusterWriteTimeout ¶
func WithClusterWriteTimeout(writeTimeout time.Duration) RedisClusterOption
WithClusterWriteTimeout 设置集群写入超时时间
type RedisComponent ¶
type RedisComponent struct {
// contains filtered or unexported fields
}
RedisComponent Redis组件
var GlobalRedisComponent *RedisComponent
全局Redis组件
func NewRedisComponent ¶
func NewRedisComponent(opts ...RedisOption) *RedisComponent
NewRedisComponent 创建Redis组件
func (*RedisComponent) GetClient ¶
func (r *RedisComponent) GetClient() *redis.Client
GetClient 获取Redis客户端
type RedisOption ¶
type RedisOption func(*RedisComponent)
RedisOption 定义Redis选项函数类型
func WithRedisMaxRetries ¶
func WithRedisMaxRetries(maxRetries int) RedisOption
WithRedisMaxRetries 设置最大重试次数
func WithRedisMaxRetryBackoff ¶
func WithRedisMaxRetryBackoff(maxRetryBackoff time.Duration) RedisOption
WithRedisMaxRetryBackoff 设置最大重试间隔时间
func WithRedisMinIdleConns ¶
func WithRedisMinIdleConns(minIdleConns int) RedisOption
WithRedisMinIdleConns 设置最小空闲连接数
func WithRedisMinRetryBackoff ¶
func WithRedisMinRetryBackoff(minRetryBackoff time.Duration) RedisOption
WithRedisMinRetryBackoff 设置最小重试间隔时间
func WithRedisPassword ¶
func WithRedisPassword(password string) RedisOption
WithRedisPassword 设置Redis密码
func WithRedisPoolTimeout ¶
func WithRedisPoolTimeout(poolTimeout time.Duration) RedisOption
WithRedisPoolTimeout 设置连接池超时时间
func WithRedisReadTimeout ¶
func WithRedisReadTimeout(readTimeout time.Duration) RedisOption
WithRedisReadTimeout 设置读取超时时间
func WithRedisWriteTimeout ¶
func WithRedisWriteTimeout(writeTimeout time.Duration) RedisOption
WithRedisWriteTimeout 设置写入超时时间