db

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDB

func GetDB() *gorm.DB

GetDB 返回单例 *gorm.DB

func GetRedis

func GetRedis() *redis.Client

GetRedis 返回单例 Redis 客户端

func InitMySQL

func InitMySQL(opts *MySQLOptions) (*gorm.DB, error)

InitMySQL 使用给定的选项创建一个新的 gorm 数据库实例.

func InitRedis

func InitRedis(opts *RedisOptions) (*redis.Client, error)

Types

type MySQLOptions

type MySQLOptions struct {
	Host                  string
	Username              string
	Password              string
	Database              string
	MaxIdleConnections    int
	MaxOpenConnections    int
	MaxConnectionLifeTime time.Duration
	LogLevel              int
}

MySQLOptions 定义 MySQL 数据库的选项.

func (*MySQLOptions) DSN

func (o *MySQLOptions) DSN() string

DSN 从 MySQLOptions 返回 DSN.

type RedisOptions

type RedisOptions struct {
	Addr         string        // "127.0.0.1:6379"
	Password     string        // 密码
	DB           int           // 数据库
	PoolSize     int           // 连接池大小
	MinIdleConns int           // 最小空闲连接数
	DialTimeout  time.Duration // 连接超时
	ReadTimeout  time.Duration // 读超时
	WriteTimeout time.Duration // 写超时
}

RedisOptions 定义 Redis 连接选项

Jump to

Keyboard shortcuts

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