From 0d2bfc7b135d0f91daf6b50b71baef95ad0aa2bd Mon Sep 17 00:00:00 2001 From: Jonson Petard <41122242+greenhat616@users.noreply.github.com> Date: Wed, 13 Sep 2023 23:44:08 +0800 Subject: [PATCH] fix(docker): export cache file --- cache/base.go | 2 +- prestart/do.go | 8 -------- prestart/init_config_driver.go | 1 + 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/cache/base.go b/cache/base.go index 7f147f5..bdad3f2 100644 --- a/cache/base.go +++ b/cache/base.go @@ -15,7 +15,7 @@ import ( var Collection *zcache.Cache[string, []byte] // DataFilePath 是缓存记录文件地址 -var DataFilePath = filepath.Join(util.MustGetExecDir(), "cache.data") +var DataFilePath = filepath.Join(util.MustGetExecDir(), "./data", "cache.data") // LoadFromDisk 用于初始化缓存驱动 func LoadFromDisk() { diff --git a/prestart/do.go b/prestart/do.go index 526b86c..3f0c021 100644 --- a/prestart/do.go +++ b/prestart/do.go @@ -1,21 +1,13 @@ package prestart import ( - "encoding/gob" "github.com/hitokoto-osc/Moe/cache" "github.com/hitokoto-osc/Moe/database" "github.com/hitokoto-osc/Moe/task" - "github.com/hitokoto-osc/Moe/task/status" - "github.com/hitokoto-osc/Moe/task/status/types" ) // Do is a func will be called at init, registering the drivers of program func Do() { - // TODO: 用更好的方法修复缓存读写问题 - gob.Register([]database.APIRecord{}) - gob.Register(types.GeneratedData{}) - gob.Register(status.TDownServerList{}) - cache.LoadFromDisk() initConfigDriver() database.InitDB() diff --git a/prestart/init_config_driver.go b/prestart/init_config_driver.go index f3919d7..b56c138 100644 --- a/prestart/init_config_driver.go +++ b/prestart/init_config_driver.go @@ -48,6 +48,7 @@ func initConfigDriver() { viper.AddConfigPath(".") viper.AddConfigPath("./conf") viper.AddConfigPath("./config") + viper.AddConfigPath("./data") // docker purpose viper.AddConfigPath("../conf") viper.AddConfigPath("../config") err := viper.ReadInConfig()