conn

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 30, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package conn 数据库配置链接以及客户端

Index

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 MySQLConn

func MySQLConn(ctx context.Context) (*gorm.DB, error)

MySQLConn 获取etcd mysql链接

func MySqlDBHandleGrpc

func MySqlDBHandleGrpc(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error)

func MysqlParamsConn

func MysqlParamsConn(ctx context.Context, mysqlConnStr string) (*gorm.DB, error)

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

func RedisConn

func RedisConn(ctx context.Context) (*redis.Client, error)

RedisConn 获取redis客户端 必须搭建etcd

func RedisParamsConn

func RedisParamsConn(ctx context.Context, redisConnAddr, redisConnPass string) (*redis.Client, error)

RedisParamsConn 获取redis客户端 redisConnAddr

Types

type GormConfig

type GormConfig func(*GormConfigs)

GormConfig gorm配置

func ConnectStr

func ConnectStr(connectStr string) GormConfig

ConnectStr 数据库地址

func MaxConns

func MaxConns(maxConns int) GormConfig

MaxConns 最大连接数

func MaxIdleConns

func MaxIdleConns(maxIdleConns int) GormConfig

MaxIdleConns 最大id数

func Provider

func Provider(provider string) GormConfig

Provider 数据库提供者

type GormConfigs

type GormConfigs struct {
	// 数据库类型
	Provider     string
	ConnectStr   string
	MaxConns     int
	MaxIdleConns int
}

GormConfigs gorm连接配置

type RedisConfig

type RedisConfig func(*redisConfigs)

RedisConfig redis config func

func RedisAddr

func RedisAddr(addr string) RedisConfig

RedisAddr redis address

func RedisPassword

func RedisPassword(pass string) RedisConfig

RedisPassword redis pass

Jump to

Keyboard shortcuts

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