Documentation
¶
Overview ¶
Package database provides database client initialization.
Package database provides database client initialization.
Index ¶
- Variables
- func CloseDB() error
- func CloseElasticsearch() error
- func CloseRedis() error
- func GenerateOrderNo(prefix string, snowId snowflake.ID) string
- func GetDB() *sgorm.DB
- func GetElasticsearch() *es.Client
- func GetRedisCli() *goredis.Client
- func GetSequenceFromSnowId(id snowflake.ID) int64
- func GetSnowId() snowflake.ID
- func GetSnowNode() *snowflake.Node
- func GetTimeFromSnowId(id snowflake.ID) time.Time
- func InitCache(cType string)
- func InitDB()
- func InitElasticsearch() *es.Client
- func InitMysql() *sgorm.DB
- func InitRabbitmq()
- func InitRedis()
- func InitSnowNode()
- func ParseSnowId(id snowflake.ID) map[string]int64
- type CacheType
- type MqCfg
- type RabbitMQ
- func (r *RabbitMQ) Close(ctx context.Context) error
- func (r *RabbitMQ) GetConnection(ctx context.Context) (*gorabbitmq.Connection, error)
- func (r *RabbitMQ) GetPoolStats(ctx context.Context) map[string]interface{}
- func (r *RabbitMQ) PutConnection(ctx context.Context, conn *gorabbitmq.Connection) error
- func (r *RabbitMQ) SendMessage(ctx context.Context, exchangeName, normalQueueName string, message string, ...) error
- type RabbitMQClient
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrCacheNotFound 未命中缓存 ErrCacheNotFound = goredis.ErrRedisNotFound )
View Source
var (
ErrRecordNotFound = sgorm.ErrRecordNotFound
)
Functions ¶
func CloseElasticsearch ¶ added in v1.3.12
func CloseElasticsearch() error
CloseElasticsearch 关闭ES客户端(空实现,仅为了保持接口一致性)
func GenerateOrderNo ¶ added in v1.3.6
GenerateOrderNo 生成带有业务含义的订单号
func GetElasticsearch ¶ added in v1.3.12
GetElasticsearch 获取ES客户端实例
func GetSequenceFromSnowId ¶ added in v1.3.6
GetSequenceFromSnowId 从雪花ID中提取序列号
func InitElasticsearch ¶ added in v1.3.12
InitElasticsearch 初始化Elasticsearch客户端
Types ¶
type CacheType ¶
type CacheType struct {
CType string // 缓存类型 memory 或 redis
Rdb *goredis.Client // 如果 CType=redis,则 Rdb 不能为空
}
CacheType 缓存类型
type MqCfg ¶ added in v1.3.6
type MqCfg struct {
ExchangeName string // 交换机名称
NormalQueueName string // 普通队列名称
Url string // RabbitMQ连接URL
DialTimeout time.Duration // 连接超时时间
IsDeadLetter bool // 是否启用死信队列
}
MqCfg 包含 RabbitMQ 配置信息
type RabbitMQ ¶ added in v1.3.23
type RabbitMQ struct {
// contains filtered or unexported fields
}
RabbitMQ 封装了 RabbitMQ 连接池及相关操作
func (*RabbitMQ) GetConnection ¶ added in v1.3.23
func (r *RabbitMQ) GetConnection(ctx context.Context) (*gorabbitmq.Connection, error)
GetConnection 从连接池获取一个 RabbitMQ 连接
func (*RabbitMQ) GetPoolStats ¶ added in v1.3.23
GetPoolStats 获取连接池统计信息
func (*RabbitMQ) PutConnection ¶ added in v1.3.23
func (r *RabbitMQ) PutConnection(ctx context.Context, conn *gorabbitmq.Connection) error
PutConnection 将 RabbitMQ 连接放回连接池
type RabbitMQClient ¶ added in v1.3.6
type RabbitMQClient struct {
// contains filtered or unexported fields
}
RabbitMQClient 封装RabbitMQ操作
func GetClient ¶ added in v1.3.6
func GetClient(ctx context.Context, cfg *MqCfg) (*RabbitMQClient, error)
GetClient 从连接池获取客户端
func (*RabbitMQClient) CloseConnection ¶ added in v1.3.6
func (c *RabbitMQClient) CloseConnection()
CloseConnection 关闭连接
Click to show internal directories.
Click to hide internal directories.