components

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: May 23, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DB

func DB(name string) *gorm.DB

保留原有的命名实例访问方法

func DefaultSlaveDB

func DefaultSlaveDB() *gorm.DB

默认实例的从库访问方法

func GetClickHouse added in v1.1.7

func GetClickHouse(name string) driver.Conn

获取指定名称的ClickHouse连接

func GetClickHouseGORMDB added in v1.1.9

func GetClickHouseGORMDB(name string) *gorm.DB

GetClickHouseGORMDB 获取指定名称的ClickHouse GORM DB

func GetDefaultClickHouse added in v1.1.7

func GetDefaultClickHouse() driver.Conn

获取默认ClickHouse连接

func GetDefaultClickHouseGORM added in v1.1.9

func GetDefaultClickHouseGORM() *gorm.DB

GetDefaultClickHouseGORM 获取默认ClickHouse GORM DB

func GetDefaultDB

func GetDefaultDB() *gorm.DB

默认实例的全局访问方法

func GinModeForEnv

func GinModeForEnv(env string) string

GinModeForEnv 根据环境变量设置Gin模式

func GormLogLevelForEnv

func GormLogLevelForEnv(env string) logger.LogLevel

GormLogLevelForEnv 根据环境变量设置Gorm日志级别

func SlaveDB

func SlaveDB(name string) *gorm.DB

ReplicaDB 获取从库连接

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连接

func (*ClickHouseComponent) Start added in v1.1.7

func (c *ClickHouseComponent) Start(ctx context.Context) error

Start 启动ClickHouse组件

func (*ClickHouseComponent) Stop added in v1.1.7

Stop 停止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实例

func (*ClickHouseGORMComponent) Start added in v1.1.9

Start 启动ClickHouse GORM组件

func (*ClickHouseGORMComponent) Stop added in v1.1.9

Stop 停止ClickHouse GORM组件

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) GetEngine

func (g *GinComponent) GetEngine() *gin.Engine

GetEngine 获取Gin引擎

func (*GinComponent) Start

func (g *GinComponent) Start(ctx context.Context) error

Start 启动Gin组件

func (*GinComponent) Stop

func (g *GinComponent) Stop(ctx context.Context) error

Stop 停止Gin组件

func (*GinComponent) Use added in v1.0.3

func (g *GinComponent) Use(middleware ...gin.HandlerFunc)

Use 添加全局中间件

type GinConfig

type GinConfig struct {
	Port            string
	Mode            string
	ShutdownTimeout time.Duration
}

GinConfig Gin配置

type GinOption

type GinOption func(*GinComponent)

GinOption 定义Gin选项函数类型

func WithGinMiddleware added in v1.0.3

func WithGinMiddleware(middleware ...gin.HandlerFunc) GinOption

WithGinMiddleware 添加全局中间件

func WithGinMode

func WithGinMode(mode string) GinOption

WithGinMode 设置Gin模式

func WithGinPort

func WithGinPort(port string) GinOption

WithGinPort 设置Gin端口

func WithGinRouter

func WithGinRouter(routerRegistrar func(*gin.Engine)) GinOption

WithGinRouter 设置路由注册函数

func WithGinShutdownTimeout

func WithGinShutdownTimeout(timeout time.Duration) GinOption

WithGinShutdownTimeout 设置关闭超时时间

type MySQLComponent

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

MySQLComponent MySQL组件

var (
	DefaultDB *MySQLComponent // 添加默认实例

)

func GetMySQLComponent

func GetMySQLComponent(name string) *MySQLComponent

获取指定实例

func NewMySQLComponent

func NewMySQLComponent(name string, config *MySQLConfig, isDefault bool) *MySQLComponent

NewMySQLComponent 创建MySQL组件

func (*MySQLComponent) Master

func (m *MySQLComponent) Master() *gorm.DB

Master 获取主库连接

func (*MySQLComponent) Slave

func (m *MySQLComponent) Slave() *gorm.DB

Replica 获取从库连接(轮询方式)

func (*MySQLComponent) Start

func (m *MySQLComponent) Start(ctx context.Context) error

Start 启动MySQL组件

func (*MySQLComponent) Stop

func (m *MySQLComponent) Stop(ctx context.Context) error

Stop 停止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集群客户端

func (*RedisClusterComponent) Start

Start 启动Redis集群组件

func (*RedisClusterComponent) Stop

Stop 停止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客户端

func (*RedisComponent) Start

func (r *RedisComponent) Start(ctx context.Context) error

Start 启动Redis组件

func (*RedisComponent) Stop

func (r *RedisComponent) Stop(ctx context.Context) error

Stop 停止Redis组件

type RedisOption

type RedisOption func(*RedisComponent)

RedisOption 定义Redis选项函数类型

func WithRedisAddr

func WithRedisAddr(addr string) RedisOption

WithRedisAddr 设置Redis地址

func WithRedisDB

func WithRedisDB(db int) RedisOption

WithRedisDB 设置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 WithRedisPoolSize

func WithRedisPoolSize(poolSize int) RedisOption

WithRedisPoolSize 设置连接池大小

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 设置写入超时时间

Jump to

Keyboard shortcuts

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