-
Notifications
You must be signed in to change notification settings - Fork 0
/
confdao.go
90 lines (74 loc) · 1.99 KB
/
confdao.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package confdao
import (
"database/sql"
"fmt"
"github.com/hopeio/cherry/_example/user/model"
"github.com/hopeio/cherry/initialize/conf_dao/gormdb/postgres"
"github.com/hopeio/cherry/initialize/conf_dao/log"
"github.com/hopeio/cherry/initialize/conf_dao/mail"
"github.com/hopeio/cherry/initialize/conf_dao/redis"
"github.com/hopeio/cherry/initialize/conf_dao/ristretto"
"github.com/hopeio/cherry/initialize/conf_dao/server"
"github.com/hopeio/cherry/utils/io/fs"
timei "github.com/hopeio/cherry/utils/time"
"runtime"
"time"
)
var (
Conf = &config{}
Dao *dao = &dao{}
)
type config struct {
//自定义的配置
Customize serverConfig
Server server.Config
Log log.Config
}
type serverConfig struct {
Volume fs.Dir
PassSalt string
// 天数
TokenMaxAge time.Duration
TokenSecret string
PageSize int8
LuosimaoSuperPW string
LuosimaoVerifyURL string
LuosimaoAPIKey string
QrCodeSaveDir fs.Dir //二维码保存路径
PrefixUrl string
FontSaveDir fs.Dir //字体保存路径
}
func (c *config) InitBeforeInject() {
c.Customize.TokenMaxAge = timei.Day
}
func (c *config) InitAfterInject() {
if runtime.GOOS == "windows" {
}
c.Customize.TokenMaxAge = timei.StdDuration(c.Customize.TokenMaxAge, time.Hour)
}
// dao dao.
type dao struct {
// GORMDB 数据库连接
GORMDB postgres.DB
StdDB *sql.DB
// RedisPool Redis连接池
Redis redis.Client
Cache ristretto.Cache[string, any]
//elastic
Mail mail.Mail `init:"config:Mail"`
}
func (d *dao) InitBeforeInject() {
d.GORMDB.Conf.Gorm.NowFunc = time.Now
}
func (d *dao) InitAfterInjectConfig() {
fmt.Println("这里后执行")
}
func (d *dao) InitAfterInject() {
db := d.GORMDB
db.Callback().Create().Remove("gorm:save_before_associations")
db.Callback().Create().Remove("gorm:save_after_associations")
db.Callback().Update().Remove("gorm:save_before_associations")
db.Callback().Update().Remove("gorm:save_after_associations")
d.StdDB, _ = db.DB.DB()
d.GORMDB.Migrator().AutoMigrate(&model.TestJson{})
}