dsn

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

* @Author: reel * @Date: 2023-05-16 20:02:15 * @LastEditors: reel * @LastEditTime: 2024-01-13 23:26:46 * @Description: 配置数据库,缓存的链接, 支持本地缓存和本地数据库

Index

Constants

View Source
const (
	DSN_TYPE_LOCAL   = "local"
	DSN_TYPE_SQLITE  = "sqlite"
	DSN_TYPE_REDIS   = "redis"
	DSN_TYPE_MYSQL   = "mysql"
	DSN_TYPE_PGSQL   = "postgres"
	MYSQL_DB_DSN_KYE = "%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=True&loc=Local"
	PGSQL_DB_DSN_KYE = "user=%s password=%s host=%s port=%s dbname=%s sslmode=disable TimeZone=Asia/Shanghai"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Dsn

type Dsn struct {
	Type string
	Path string
	Name string
	Host string
	Port string
	User string
	Pwd  string
	Log  logx.Logger
	// contains filtered or unexported fields
}

func CopyDsn added in v1.1.0

func CopyDsn(dsn *Dsn) *Dsn

func NewCacheDsn

func NewCacheDsn() *Dsn

func NewDBDsn

func NewDBDsn() *Dsn

func NewPGDsn

func NewPGDsn() *Dsn
func (d *Dsn) Link() string

TODO: 增加 mysql postgre redis 等

type DsnFunc

type DsnFunc func(Dsn *Dsn)

func PGDefaultDsn

func PGDefaultDsn() DsnFunc

配置默认端口为 5432

func SetHost

func SetHost(host string) DsnFunc
func SetLink(link string) DsnFunc

直接设置数据库链接,而不需要再设置主机端口等 TODO: 配置 redis, mysql 等数据库支持

func SetLog

func SetLog(log logx.Logger) DsnFunc

func SetName

func SetName(name string) DsnFunc

设置 db 名称

func SetPath

func SetPath(path string) DsnFunc

设置本地 db 路径

func SetPort

func SetPort(port string) DsnFunc

func SetPwd

func SetPwd(pwd string) DsnFunc

func SetType

func SetType(t string) DsnFunc

func SetUser

func SetUser(user string) DsnFunc

Jump to

Keyboard shortcuts

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