db

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: MIT Imports: 8 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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