Documentation
¶
Index ¶
Constants ¶
View Source
const (
// Path 配置 & .db 目录
Path = "data"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Type string `json:"type"` // 数据库类型: "mysql" 或 "sqlite",默认 "sqlite"
Host string `json:"host"` // MySQL: 数据库主机地址
Port string `json:"port"` // MySQL: 数据库端口号
User string `json:"user"` // MySQL: 用户名
Password string `json:"password"` // MySQL: 密码
Database string `json:"database"` // MySQL: 数据库名(必填)
DBFile string `json:"db_file"` // SQLite: mfa.db
TablePrefix string `json:"table_prefix"` // 表名前缀(可选)
MaxIdleConn int `json:"max_idle_conn"` // 数据库连接池中的最大空闲连接数
MaxOpenConn int `json:"max_open_conn"` // 数据库连接池中的最大打开连接数
ConnMaxLifetime int `json:"conn_max_lifetime"` // 连接的最大寿命, 超过这个时间会被关闭
}
Config 定义数据库配置结构体,用于支持 MySQL 或 SQLite
func LoadOrCreateConfig ¶
LoadOrCreateConfig 加载配置文件 如果配置文件不存在,将根据示例文件(examplePath)创建一个新的配置文件,并提示用户修改后重新运行程序
参数: - examplePath: 示例配置文件路径,通常为 example.config.json
返回: - *Config: 解析后的配置结构体指针 - error: 错误信息
Click to show internal directories.
Click to hide internal directories.