diff --git a/mayfly_go_web/src/common/config.ts b/mayfly_go_web/src/common/config.ts index 3b5aac52..12781412 100644 --- a/mayfly_go_web/src/common/config.ts +++ b/mayfly_go_web/src/common/config.ts @@ -15,7 +15,7 @@ const config = { baseWsUrl: `${(window as any).globalConfig.BaseWsUrl || `${location.protocol == 'https:' ? 'wss:' : 'ws:'}//${getBaseApiUrl()}`}/api`, // 系统版本 - version: 'v1.6.2', + version: 'v1.7.0', }; export default config; diff --git a/server/go.mod b/server/go.mod index af7eccaa..9c17e884 100644 --- a/server/go.mod +++ b/server/go.mod @@ -31,7 +31,6 @@ require ( go.mongodb.org/mongo-driver v1.13.1 // mongo golang.org/x/crypto v0.18.0 // ssh golang.org/x/oauth2 v0.15.0 - golang.org/x/sync v0.1.0 gopkg.in/yaml.v3 v3.0.1 // gorm gorm.io/driver/mysql v1.5.2 @@ -83,6 +82,7 @@ require ( golang.org/x/exp v0.0.0-20230519143937-03e91628a987 golang.org/x/image v0.13.0 // indirect golang.org/x/net v0.19.0 // indirect + golang.org/x/sync v0.1.0 // indirect golang.org/x/sys v0.16.0 // indirect golang.org/x/text v0.14.0 // indirect google.golang.org/appengine v1.6.7 // indirect diff --git a/server/pkg/cache/str_cache.go b/server/pkg/cache/str_cache.go index 522a4549..aa198376 100644 --- a/server/pkg/cache/str_cache.go +++ b/server/pkg/cache/str_cache.go @@ -11,7 +11,7 @@ var tm *TimedCache // 如果系统有设置redis信息,则从redis获取,否则本机内存获取 func GetStr(key string) string { - if !useRedisCache() { + if !UseRedisCache() { checkCache() val, _ := tm.Get(key) if val == nil { @@ -41,7 +41,7 @@ func GetInt(key string) int { // 如果系统有设置redis信息,则使用redis存,否则存于本机内存。duration == -1则为永久缓存 func SetStr(key, value string, duration time.Duration) error { - if !useRedisCache() { + if !UseRedisCache() { checkCache() return tm.Add(key, value, duration) } @@ -50,7 +50,7 @@ func SetStr(key, value string, duration time.Duration) error { // 删除指定key func Del(key string) { - if !useRedisCache() { + if !UseRedisCache() { checkCache() tm.Delete(key) return @@ -58,12 +58,12 @@ func Del(key string) { rediscli.Del(key) } +func UseRedisCache() bool { + return rediscli.GetCli() != nil +} + func checkCache() { if tm == nil { tm = NewTimedCache(time.Minute*time.Duration(5), 30*time.Second) } } - -func useRedisCache() bool { - return rediscli.GetCli() != nil -} diff --git a/server/pkg/config/app.go b/server/pkg/config/app.go index 8f60a2ac..090b3b2f 100644 --- a/server/pkg/config/app.go +++ b/server/pkg/config/app.go @@ -4,7 +4,7 @@ import "fmt" const ( AppName = "mayfly-go" - Version = "v1.6.2" + Version = "v1.7.0" ) func GetAppInfo() string { diff --git a/server/pkg/utils/cryptox/cryptox.go b/server/pkg/utils/cryptox/cryptox.go index b8efec79..06f00f97 100644 --- a/server/pkg/utils/cryptox/cryptox.go +++ b/server/pkg/utils/cryptox/cryptox.go @@ -142,32 +142,48 @@ const ( // 获取系统的RSA公钥 func GetRsaPublicKey() (string, error) { - content, err := os.ReadFile(publicKeyFile) - if err != nil { + if cache.UseRedisCache() { publicKey := cache.GetStr(publicKeyK) if publicKey != "" { return publicKey, nil } - _, pubKey, err := GenerateAndSaveRSAKey() - return pubKey, err + } else { + content, err := os.ReadFile(publicKeyFile) + if err != nil { + publicKey := cache.GetStr(publicKeyK) + if publicKey != "" { + return publicKey, nil + } + } else { + return string(content), nil + } } - return string(content), nil + _, pubKey, err := GenerateAndSaveRSAKey() + return pubKey, err } // 获取系统私钥 func GetRsaPrivateKey() (string, error) { - content, err := os.ReadFile(privateKeyFile) - if err != nil { - privateKey := cache.GetStr(privateKeyK) - if privateKey != "" { - return privateKey, nil + if cache.UseRedisCache() { + priKey := cache.GetStr(privateKeyK) + if priKey != "" { + return priKey, nil + } + } else { + content, err := os.ReadFile(privateKeyFile) + if err != nil { + priKey := cache.GetStr(privateKeyK) + if priKey != "" { + return priKey, nil + } + } else { + return string(content), nil } - privateKey, _, err := GenerateAndSaveRSAKey() - return privateKey, err } - return string(content), nil + priKey, _, err := GenerateAndSaveRSAKey() + return priKey, err } // 生成并保存rsa key,优先保存于磁盘,若磁盘保存失败,则保存至缓存 @@ -179,6 +195,14 @@ func GenerateAndSaveRSAKey() (string, string, error) { return "", "", err } + // 如果使用了redis缓存,则优先存入redis + if cache.UseRedisCache() { + logx.Debug("系统配置了redis, rsa存入redis") + cache.SetStr(privateKeyK, privateKey, -1) + cache.SetStr(publicKeyK, publicKey, -1) + return privateKey, publicKey, nil + } + err = os.WriteFile(privateKeyFile, []byte(privateKey), 0644) if err != nil { logx.ErrorTrace("RSA私钥写入磁盘文件失败, 使用缓存存储该私钥", err) diff --git a/server/resources/script/sql/v1.6.2.sql b/server/resources/script/sql/v1.7.0.sql similarity index 100% rename from server/resources/script/sql/v1.6.2.sql rename to server/resources/script/sql/v1.7.0.sql