Documentation ¶
Overview ¶
Package conn 数据库配置链接以及客户端
Index ¶
- Constants
- func DBHandleGrpcInterceptor() grpc.UnaryServerInterceptor
- func MySQLConn(ctx context.Context) (*gorm.DB, error)
- func MySqlDBHandleGrpc(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, ...) (interface{}, error)
- func MysqlParamsConn(ctx context.Context, mysqlConnStr string) (*gorm.DB, error)
- func PrepareGorm(confs ...GormConfig) (db *gorm.DB, err error)
- func PrepareRedis(ctx context.Context, redisConfs ...RedisConfig) (redisClient *redis.Client, err error)
- func RedisConn(ctx context.Context) (*redis.Client, error)
- func RedisParamsConn(ctx context.Context, redisConnAddr, redisConnPass string) (*redis.Client, error)
- type GormConfig
- type GormConfigs
- type RedisConfig
Constants ¶
View Source
const ( // DefaultMaxIdleCount 默认最大闲置连接数 DefaultMaxIdleCount = 10 // DefaultMaxActiveCount 默认最大活动连接数 DefaultMaxActiveCount = 100 // DefaultDialConnectTimeout 默认拨号超时 DefaultDialConnectTimeout = 5 // DefaultDialReadTimeout 默认读超时 DefaultDialReadTimeout = 1 // DefaultDialWriteTimeout 默认写超时 DefaultDialWriteTimeout = 1 // DefaultIdelTimeout 默认闲置超时 DefaultIdelTimeout = 300 // DefaultConnCheckTime 默认连接检查时间间隔 DefaultConnCheckTime = 120 )
Variables ¶
This section is empty.
Functions ¶
func DBHandleGrpcInterceptor ¶
func DBHandleGrpcInterceptor() grpc.UnaryServerInterceptor
func MySqlDBHandleGrpc ¶
func MySqlDBHandleGrpc(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error)
func MysqlParamsConn ¶
MysqlParamsConn 通过参数获取链接 mysqlConnStr 参考 root:1234@tcp(rds.aliyuncs.com:3306)/ context 必须通过incomingCtx设定db_code
func PrepareGorm ¶
func PrepareGorm(confs ...GormConfig) (db *gorm.DB, err error)
PrepareGorm 准备gorm连接
func PrepareRedis ¶
func PrepareRedis(ctx context.Context, redisConfs ...RedisConfig) (redisClient *redis.Client, err error)
PrepareRedis 准备redis连接
Types ¶
type GormConfigs ¶
type GormConfigs struct { // 数据库类型 Provider string ConnectStr string MaxConns int MaxIdleConns int }
GormConfigs gorm连接配置
Click to show internal directories.
Click to hide internal directories.