config

package
v0.0.0-...-1b2adb6 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FileWithLineNum

func FileWithLineNum() string

FileWithLineNum 获取调用堆栈信息

Types

type DBLogLevel

type DBLogLevel string
const (
	Info   DBLogLevel = "info"
	Warn   DBLogLevel = "warn"
	Error  DBLogLevel = "error"
	Silent DBLogLevel = "silent"
)

func (DBLogLevel) ToGormLogLevel

func (l DBLogLevel) ToGormLogLevel() (logLevel logger.LogLevel)

type DBType

type DBType string
const (
	Mysql  DBType = "mysql"
	Pgsql  DBType = "postgres"
	Sqlite DBType = "sqlite3"
	NoType DBType = "none"
)

type DatabaseConf

type DatabaseConf struct {
	Host          string     `json:",env=DATABASE_HOST"`
	Port          int        `json:",env=DATABASE_PORT"`
	Username      string     `json:",default=root,env=DATABASE_USERNAME"`
	Password      string     `json:",optional,env=DATABASE_PASSWORD"`
	DBName        string     `json:",default=sa,env=DATABASE_DBNAME"`
	SSLMode       string     `json:",optional,env=DATABASE_SSL_MODE"`
	Type          DBType     `json:",default=mysql,options=[mysql,postgres,sqlite3],env=DATABASE_TYPE"`
	MaxOpenConn   int        `json:",optional,default=100,env=DATABASE_MAX_OPEN_CONN"`
	CacheTime     int        `json:",optional,default=10,env=DATABASE_CACHE_TIME"`
	DBPath        string     `json:",optional,env=DATABASE_DBPATH"`
	MysqlConfig   string     `json:",optional,env=DATABASE_MYSQL_CONFIG"`
	PGConfig      string     `json:",optional,env=DATABASE_PG_CONFIG"`
	SqliteConfig  string     `json:",optional,env=DATABASE_SQLITE_CONFIG"`
	LogLevel      DBLogLevel `json:",default=info,options=[info,warn,error,silent],env=DATABASE_LOG_LEVEL"` // 日志级别,枚举(info、warn、error和silent)
	SlowThreshold int        `json:",optional,default=1000"`                                                // 记录慢查询阈值,单位毫秒
}

DatabaseConf stores database configurations.

func (DatabaseConf) DBOpen

func (c DatabaseConf) DBOpen(opts ...gorm.Option) (db *gorm.DB)

Open initialize db session based on dialer

func (DatabaseConf) GetDSN

func (c DatabaseConf) GetDSN() string

GetDSN returns DSN according to the database type.

func (DatabaseConf) GetLogger

func (c DatabaseConf) GetLogger() logger.Interface

func (DatabaseConf) MysqlDSN

func (c DatabaseConf) MysqlDSN() string

MysqlDSN returns mysql DSN.

func (DatabaseConf) NewCacheDriver deprecated

func (c DatabaseConf) NewCacheDriver(redisConf redis2.RedisConf) *gorm.DB

Deprecated: NewCacheDriver returns a Gorm driver with cache. 不太稳定,不建议使用

func (DatabaseConf) NewDriver

func (c DatabaseConf) NewDriver() (db *gorm.DB)

NewDriver returns a Gorm driver without cache.

func (DatabaseConf) PostgresDSN

func (c DatabaseConf) PostgresDSN() string

PostgresDSN returns Postgres DSN.

func (DatabaseConf) SqliteDSN

func (c DatabaseConf) SqliteDSN() string

SqliteDSN returns Sqlite DSN.

type DatabaseLogger

type DatabaseLogger struct {
	LogLevel      logger.LogLevel
	SlowThreshold time.Duration
}

DatabaseLogger 日志记录器

func NewDatabaseLogger

func NewDatabaseLogger(logLevel logger.LogLevel, slowThreshold time.Duration) *DatabaseLogger

NewDatabaseLogger 新建日志记录器

func (*DatabaseLogger) Error

func (l *DatabaseLogger) Error(ctx context.Context, msg string, data ...interface{})

Error Error日志记录

func (*DatabaseLogger) Info

func (l *DatabaseLogger) Info(ctx context.Context, msg string, data ...interface{})

Info Info日志记录

func (*DatabaseLogger) LogMode

func (l *DatabaseLogger) LogMode(level logger.LogLevel) logger.Interface

LogMode 设置日志记录模式

func (*DatabaseLogger) Trace

func (l *DatabaseLogger) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)

Trace Trace日志记录

func (*DatabaseLogger) Warn

func (l *DatabaseLogger) Warn(ctx context.Context, msg string, data ...interface{})

Warn Warn日志记录

Jump to

Keyboard shortcuts

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