mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-03 16:00:25 +08:00
feat: 支持sqlite存储数据
This commit is contained in:
@@ -52,6 +52,7 @@ type Config struct {
|
||||
Jwt Jwt `yaml:"jwt"`
|
||||
Aes Aes `yaml:"aes"`
|
||||
Mysql Mysql `yaml:"mysql"`
|
||||
Sqlite Sqlite `yaml:"sqlite"`
|
||||
Redis Redis `yaml:"redis"`
|
||||
Log Log `yaml:"log"`
|
||||
}
|
||||
@@ -70,6 +71,7 @@ func (c *Config) IfBlankDefaultValue() {
|
||||
c.Server.Default()
|
||||
c.Jwt.Default()
|
||||
c.Mysql.Default()
|
||||
c.Sqlite.Default()
|
||||
}
|
||||
|
||||
// 配置文件内容校验
|
||||
@@ -109,6 +111,11 @@ func (c *Config) ReplaceOsEnv() {
|
||||
c.Mysql.Password = dbPwd
|
||||
}
|
||||
|
||||
sqlitePath := os.Getenv("MAYFLY_SQLITE_PATH")
|
||||
if sqlitePath != "" {
|
||||
c.Sqlite.Path = sqlitePath
|
||||
}
|
||||
|
||||
aesKey := os.Getenv("MAYFLY_AES_KEY")
|
||||
if aesKey != "" {
|
||||
c.Aes.Key = aesKey
|
||||
|
||||
22
server/pkg/config/sqlite.go
Normal file
22
server/pkg/config/sqlite.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package config
|
||||
|
||||
import "mayfly-go/pkg/logx"
|
||||
|
||||
type Sqlite struct {
|
||||
Path string `mapstructure:"path" json:"path" yaml:"path"`
|
||||
MaxIdleConns int `mapstructure:"max-idle-conns" json:"maxIdleConns" yaml:"max-idle-conns"`
|
||||
MaxOpenConns int `mapstructure:"max-open-conns" json:"maxOpenConns" yaml:"max-open-conns"`
|
||||
}
|
||||
|
||||
func (m *Sqlite) Default() {
|
||||
if m.Path == "" {
|
||||
m.Path = "./mayfly-go.sqlite"
|
||||
logx.Warnf("未配置sqlite.path, 默认值: %s", m.Path)
|
||||
}
|
||||
if m.MaxIdleConns == 0 {
|
||||
m.MaxIdleConns = 5
|
||||
}
|
||||
if m.MaxOpenConns == 0 {
|
||||
m.MaxOpenConns = m.MaxIdleConns
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user