mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-03 16:00:25 +08:00
feat: v1.7.0
This commit is contained in:
@@ -15,7 +15,7 @@ const config = {
|
|||||||
baseWsUrl: `${(window as any).globalConfig.BaseWsUrl || `${location.protocol == 'https:' ? 'wss:' : 'ws:'}//${getBaseApiUrl()}`}/api`,
|
baseWsUrl: `${(window as any).globalConfig.BaseWsUrl || `${location.protocol == 'https:' ? 'wss:' : 'ws:'}//${getBaseApiUrl()}`}/api`,
|
||||||
|
|
||||||
// 系统版本
|
// 系统版本
|
||||||
version: 'v1.6.2',
|
version: 'v1.7.0',
|
||||||
};
|
};
|
||||||
|
|
||||||
export default config;
|
export default config;
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ require (
|
|||||||
go.mongodb.org/mongo-driver v1.13.1 // mongo
|
go.mongodb.org/mongo-driver v1.13.1 // mongo
|
||||||
golang.org/x/crypto v0.18.0 // ssh
|
golang.org/x/crypto v0.18.0 // ssh
|
||||||
golang.org/x/oauth2 v0.15.0
|
golang.org/x/oauth2 v0.15.0
|
||||||
golang.org/x/sync v0.1.0
|
|
||||||
gopkg.in/yaml.v3 v3.0.1
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
// gorm
|
// gorm
|
||||||
gorm.io/driver/mysql v1.5.2
|
gorm.io/driver/mysql v1.5.2
|
||||||
@@ -83,6 +82,7 @@ require (
|
|||||||
golang.org/x/exp v0.0.0-20230519143937-03e91628a987
|
golang.org/x/exp v0.0.0-20230519143937-03e91628a987
|
||||||
golang.org/x/image v0.13.0 // indirect
|
golang.org/x/image v0.13.0 // indirect
|
||||||
golang.org/x/net v0.19.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/sys v0.16.0 // indirect
|
||||||
golang.org/x/text v0.14.0 // indirect
|
golang.org/x/text v0.14.0 // indirect
|
||||||
google.golang.org/appengine v1.6.7 // indirect
|
google.golang.org/appengine v1.6.7 // indirect
|
||||||
|
|||||||
14
server/pkg/cache/str_cache.go
vendored
14
server/pkg/cache/str_cache.go
vendored
@@ -11,7 +11,7 @@ var tm *TimedCache
|
|||||||
|
|
||||||
// 如果系统有设置redis信息,则从redis获取,否则本机内存获取
|
// 如果系统有设置redis信息,则从redis获取,否则本机内存获取
|
||||||
func GetStr(key string) string {
|
func GetStr(key string) string {
|
||||||
if !useRedisCache() {
|
if !UseRedisCache() {
|
||||||
checkCache()
|
checkCache()
|
||||||
val, _ := tm.Get(key)
|
val, _ := tm.Get(key)
|
||||||
if val == nil {
|
if val == nil {
|
||||||
@@ -41,7 +41,7 @@ func GetInt(key string) int {
|
|||||||
|
|
||||||
// 如果系统有设置redis信息,则使用redis存,否则存于本机内存。duration == -1则为永久缓存
|
// 如果系统有设置redis信息,则使用redis存,否则存于本机内存。duration == -1则为永久缓存
|
||||||
func SetStr(key, value string, duration time.Duration) error {
|
func SetStr(key, value string, duration time.Duration) error {
|
||||||
if !useRedisCache() {
|
if !UseRedisCache() {
|
||||||
checkCache()
|
checkCache()
|
||||||
return tm.Add(key, value, duration)
|
return tm.Add(key, value, duration)
|
||||||
}
|
}
|
||||||
@@ -50,7 +50,7 @@ func SetStr(key, value string, duration time.Duration) error {
|
|||||||
|
|
||||||
// 删除指定key
|
// 删除指定key
|
||||||
func Del(key string) {
|
func Del(key string) {
|
||||||
if !useRedisCache() {
|
if !UseRedisCache() {
|
||||||
checkCache()
|
checkCache()
|
||||||
tm.Delete(key)
|
tm.Delete(key)
|
||||||
return
|
return
|
||||||
@@ -58,12 +58,12 @@ func Del(key string) {
|
|||||||
rediscli.Del(key)
|
rediscli.Del(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func UseRedisCache() bool {
|
||||||
|
return rediscli.GetCli() != nil
|
||||||
|
}
|
||||||
|
|
||||||
func checkCache() {
|
func checkCache() {
|
||||||
if tm == nil {
|
if tm == nil {
|
||||||
tm = NewTimedCache(time.Minute*time.Duration(5), 30*time.Second)
|
tm = NewTimedCache(time.Minute*time.Duration(5), 30*time.Second)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func useRedisCache() bool {
|
|
||||||
return rediscli.GetCli() != nil
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import "fmt"
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
AppName = "mayfly-go"
|
AppName = "mayfly-go"
|
||||||
Version = "v1.6.2"
|
Version = "v1.7.0"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetAppInfo() string {
|
func GetAppInfo() string {
|
||||||
|
|||||||
@@ -142,32 +142,48 @@ const (
|
|||||||
|
|
||||||
// 获取系统的RSA公钥
|
// 获取系统的RSA公钥
|
||||||
func GetRsaPublicKey() (string, error) {
|
func GetRsaPublicKey() (string, error) {
|
||||||
content, err := os.ReadFile(publicKeyFile)
|
if cache.UseRedisCache() {
|
||||||
if err != nil {
|
|
||||||
publicKey := cache.GetStr(publicKeyK)
|
publicKey := cache.GetStr(publicKeyK)
|
||||||
if publicKey != "" {
|
if publicKey != "" {
|
||||||
return publicKey, nil
|
return publicKey, nil
|
||||||
}
|
}
|
||||||
_, pubKey, err := GenerateAndSaveRSAKey()
|
} else {
|
||||||
return pubKey, err
|
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) {
|
func GetRsaPrivateKey() (string, error) {
|
||||||
content, err := os.ReadFile(privateKeyFile)
|
if cache.UseRedisCache() {
|
||||||
if err != nil {
|
priKey := cache.GetStr(privateKeyK)
|
||||||
privateKey := cache.GetStr(privateKeyK)
|
if priKey != "" {
|
||||||
if privateKey != "" {
|
return priKey, nil
|
||||||
return privateKey, 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,优先保存于磁盘,若磁盘保存失败,则保存至缓存
|
// 生成并保存rsa key,优先保存于磁盘,若磁盘保存失败,则保存至缓存
|
||||||
@@ -179,6 +195,14 @@ func GenerateAndSaveRSAKey() (string, string, error) {
|
|||||||
return "", "", err
|
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)
|
err = os.WriteFile(privateKeyFile, []byte(privateKey), 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.ErrorTrace("RSA私钥写入磁盘文件失败, 使用缓存存储该私钥", err)
|
logx.ErrorTrace("RSA私钥写入磁盘文件失败, 使用缓存存储该私钥", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user