connecter

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DatabaseConnection

type DatabaseConnection interface {
	Type() DatabaseType
	Connect() error
	Close() error
	HealthCheck(ctx context.Context) error
	GetClient() interface{}
}

DatabaseConnection 数据库连接接口

type DatabaseType

type DatabaseType string

DatabaseType 数据库类型

const (
	MySQL DatabaseType = "mysql"
	Redis DatabaseType = "redis"
)

type MySQLConfig

type MySQLConfig struct {
	Host                  string        `json:"host" mapstructure:"host"`
	Username              string        `json:"username" mapstructure:"username"`
	Password              string        `json:"password" mapstructure:"password"`
	Database              string        `json:"database" mapstructure:"database"`
	MaxIdleConnections    int           `json:"max-idle-connections" mapstructure:"max-idle-connections"`
	MaxOpenConnections    int           `json:"max-open-connections" mapstructure:"max-open-connections"`
	MaxConnectionLifeTime time.Duration `json:"max-connection-life-time" mapstructure:"max-connection-life-time"`
	LogLevel              int           `json:"log-level" mapstructure:"log-level"`
	Logger                logger.Interface
}

MySQLConfig MySQL 数据库配置

type MySQLConnection

type MySQLConnection struct {
	// contains filtered or unexported fields
}

MySQLConnection MySQL 连接实现

func NewMySQLConnection

func NewMySQLConnection(config *MySQLConfig) *MySQLConnection

NewMySQLConnection 创建 MySQL 连接

func (*MySQLConnection) Close

func (m *MySQLConnection) Close() error

Close 关闭 MySQL 连接

func (*MySQLConnection) Connect

func (m *MySQLConnection) Connect() error

Connect 连接 MySQL 数据库

func (*MySQLConnection) GetClient

func (m *MySQLConnection) GetClient() interface{}

GetClient 获取 MySQL 客户端

func (*MySQLConnection) HealthCheck

func (m *MySQLConnection) HealthCheck(ctx context.Context) error

HealthCheck 检查 MySQL 连接是否健康

func (*MySQLConnection) Type

func (m *MySQLConnection) Type() DatabaseType

Type 返回数据库类型

type RedisConfig

type RedisConfig struct {
	Host                  string   `json:"host" mapstructure:"host"`
	Port                  int      `json:"port" mapstructure:"port"`
	Addrs                 []string `json:"addrs" mapstructure:"addrs"`
	Password              string   `json:"password" mapstructure:"password"`
	Database              int      `json:"database" mapstructure:"database"`
	MaxIdle               int      `json:"max-idle" mapstructure:"max-idle"`
	MaxActive             int      `json:"max-active" mapstructure:"max-active"`
	Timeout               int      `json:"timeout" mapstructure:"timeout"`
	EnableCluster         bool     `json:"enable-cluster" mapstructure:"enable-cluster"`
	UseSSL                bool     `json:"use-ssl" mapstructure:"use-ssl"`
	SSLInsecureSkipVerify bool     `json:"ssl-insecure-skip-verify" mapstructure:"ssl-insecure-skip-verify"`
}

RedisConfig Redis 数据库配置

type RedisConnection

type RedisConnection struct {
	// contains filtered or unexported fields
}

RedisConnection Redis 连接实现

func NewRedisConnection

func NewRedisConnection(config *RedisConfig) *RedisConnection

NewRedisConnection 创建 Redis 连接

func (*RedisConnection) Close

func (r *RedisConnection) Close() error

Close 关闭 Redis 连接

func (*RedisConnection) Connect

func (r *RedisConnection) Connect() error

Connect 连接 Redis 数据库

func (*RedisConnection) GetClient

func (r *RedisConnection) GetClient() interface{}

GetClient 获取 Redis 客户端

func (*RedisConnection) HealthCheck

func (r *RedisConnection) HealthCheck(ctx context.Context) error

HealthCheck 检查 Redis 连接是否健康

func (*RedisConnection) Type

func (r *RedisConnection) Type() DatabaseType

Type 返回数据库类型

Jump to

Keyboard shortcuts

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