database/define.go

112 lines
4.8 KiB
Go
Raw Normal View History

2022-05-15 11:27:28 +08:00
// Package mysql...
//
// Description : 数据定义
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2021-03-01 9:27 下午
package mysql
import (
"git.zhangdeman.cn/zhangdeman/logger"
"go.uber.org/zap/zapcore"
)
// DBConfig 数据库连接的配置
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 9:32 下午 2021/3/1
type DBConfig struct {
2022-06-05 19:07:25 +08:00
Host string `json:"host" yaml:"host"` // 主机
Port int `json:"port" yaml:"port"` // 端口
Database string `json:"database" yaml:"database"` // 数据库
Username string `json:"username" yaml:"username"` // 账号
Password string `json:"password" yaml:"password"` // 密码
Charset string `json:"charset" yaml:"charset"` // 编码
Connection Connection `json:"connection" yaml:"connection"` // 连接数量配置
}
2022-05-15 11:27:28 +08:00
// LogConfig 日志配置
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 10:51 下午 2021/3/1
type LogConfig struct {
2022-06-12 18:26:19 +08:00
Name string `json:"name" yaml:"name"` // 日志文件名
Path string `json:"path" yaml:"path"` // 日志文件路径
Format string `json:"format" yaml:"format"` // 文件格式
TimeIntervalType logger.TimeIntervalType `json:"time_interval_type" yaml:"time_interval_type"` // 日志切割规则
DivisionChar string `json:"division_char" yaml:"division_char"` // 文件名分隔符
LogLevel zapcore.Level `json:"log_level" yaml:"log_level"` // 日志等级
Console bool `json:"console" yaml:"console"` // 是否进行控制台日志输出
UseJson bool `json:"use_json" yaml:"use_json"` // 日志是否使用JSON格式
FileLine bool `json:"file_line" yaml:"file_line"` // 日志是否打印行号
MessageKey string `json:"message_key" yaml:"message_key"` // message 字段
LevelKey string `json:"level_key" yaml:"level_key"` // level 字段
TimeKey string `json:"time_key" yaml:"time_key"` // 时间字段
CallerKey string `json:"caller_key" yaml:"caller_key"` // 记录日志的文件的代码行数
UseShortFile bool `json:"use_short_file" yaml:"use_short_file"` // 是否使用短文件格式
CallerSkip int `json:"caller_skip" yaml:"caller_skip"` // 日志记录的文件跳过多少层
MaxAge int `json:"max_age" yaml:"max_age"` // 日志最长保存时间, 单位 : 秒
2022-05-15 11:27:28 +08:00
}
2022-06-09 14:58:01 +08:00
// cfgFile 配置文件定义
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 14:47 2022/6/9
type cfgFile struct {
2022-06-11 19:05:54 +08:00
Flag string `json:"flag"` // 数据库标识
Path string `json:"path"` // 配置文件路径
Type string `json:"type"` // 配置文件类型
Config Database `json:"config"` // 解析之后的配置文件
2022-06-09 14:58:01 +08:00
}
const (
// FileTypeYml tml
FileTypeYml = "yml"
// FileTypeYaml yaml
FileTypeYaml = "yaml"
// FileTypeJson json
FileTypeJson = "json"
)
// Database 数据库配置
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 15:19 2022/6/9
type Database struct {
2022-06-12 18:26:19 +08:00
Logger *LogConfig `json:"logger" yaml:"logger"` // 日志配置
Master *Mysql `json:"master" yaml:"master"` // 主库配置
Slave *Mysql `json:"slave" yaml:"slave"` // 从库配置
}
// Mysql ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:44 2022/5/14
type Mysql struct {
Host string `json:"host" yaml:"host"` // 数据库地址
Port int `json:"port" yaml:"port"` // 数据库端口
Username string `json:"username" yaml:"username"` // 用户名
Password string `json:"password" yaml:"password"` // 密码
Database string `json:"database" yaml:"database"` // 数据库
Charset string `json:"charset" yaml:"charset"` // 数据库编码
Connection *Connection `json:"connection" yaml:"connection"` // 连接配置
LogFileName string `json:"log_file_name" yaml:"log_file_name"` // 日志文件名
2022-06-11 19:05:54 +08:00
Timezone string `json:"timezone" yaml:"timezone"` // 时区
}
// Connection 连接数配置
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 15:18 2022/6/9
type Connection struct {
MaxOpen int `json:"max_open" yaml:"max_open"` // 最大打开连接数
MaxIdle int `json:"max_idle" yaml:"max_idle"` // 最大的处理连接数
}