From 5c5f5908aa422564f07374c584157db87a2592f1 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 16 Oct 2026 12:28:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/conf/app.yaml | 4 ++-- pub/common/utils/strings.go | 16 +++++++++++++--- web/conf/web.yaml | 4 ++-- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/conf/app.yaml b/app/conf/app.yaml index 6ec4dee..9dcab2f 100644 --- a/app/conf/app.yaml +++ b/app/conf/app.yaml @@ -4,8 +4,8 @@ redis: passwd: "Redis@fish2026!" subscribe: true mongodb: - addr: "mongodb://admin:3NjreBBLVOkptSWbV%21@172.104.56.78:47018,172.104.56.119:47018,172.104.56.146:47018/web_huangguo2?replicaSet=web_jiqun3&maxPoolSize=200&connectTimeout=30&authSource=web_huangguo2" - logaddr: "mongodb://admin:3NjreBBLVOkptSWbV%21@172.104.56.78:47018,172.104.56.119:47018,172.104.56.146:47018/web_huangguo2_log?replicaSet=web_jiqun3&maxPoolSize=200&connectTimeout=30&authSource=web_huangguo2" + addr: "mongodb://web_huangguo2:xDdEkf6m0HDpkEpxpphi@172.104.52.130:27017,172.104.52.26:27017,172.104.52.242:27017/web_huangguo2?replicaSet=fish0&maxPoolSize=200&connectTimeout=30&authSource=web_huangguo2" + logaddr: "mongodb://web_huangguo2:xDdEkf6m0HDpkEpxpphi@172.104.52.130:27017,172.104.52.26:27017,172.104.52.242:27017/web_huangguo2_log?replicaSet=fish0&maxPoolSize=200&connectTimeout=30&authSource=web_huangguo2" es: addr: "http://139.162.47.194:9200" user: "elastic" diff --git a/pub/common/utils/strings.go b/pub/common/utils/strings.go index 9811f64..ca0743b 100644 --- a/pub/common/utils/strings.go +++ b/pub/common/utils/strings.go @@ -79,6 +79,16 @@ func GetRandomLetters(n int) string { return string(b) } +// GetRandomAlphanumeric 生成 n 位大小写字母 + 数字随机串 +func GetRandomAlphanumeric(n int) string { + const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" + b := make([]byte, n) + for i := range b { + b[i] = chars[rand.IntN(len(chars))] + } + return string(b) +} + func GetSlugInfo(text string) string { return SanitizeSlug(slug.Make(text)) } @@ -114,12 +124,12 @@ func IsSlugAllDigits(s string) bool { } // RandomSlugLength 随机 slug 长度 -const RandomSlugLength = 8 +const RandomSlugLength = 10 -// MakeRandomSlug 生成唯一的随机 slug(8 位小写字母);exists 返回 true 表示已被占用。 +// MakeRandomSlug 生成唯一的随机 slug(10 位大小写字母+数字混合);exists 返回 true 表示已被占用。 func MakeRandomSlug(exists func(string) bool) string { for { - s := strings.ToLower(GetRandomLetters(RandomSlugLength)) + s := GetRandomAlphanumeric(RandomSlugLength) if !exists(s) { return s } diff --git a/web/conf/web.yaml b/web/conf/web.yaml index ff6418b..6687d83 100644 --- a/web/conf/web.yaml +++ b/web/conf/web.yaml @@ -4,8 +4,8 @@ redis: passwd: "Redis@fish2026!" subscribe: true mongodb: - addr: "mongodb://admin:3NjreBBLVOkptSWbV%21@172.104.56.78:47018,172.104.56.119:47018,172.104.56.146:47018/web_huangguo2?replicaSet=web_jiqun3&maxPoolSize=200&connectTimeout=30&authSource=web_huangguo2" - logaddr: "mongodb://admin:3NjreBBLVOkptSWbV%21@172.104.56.78:47018,172.104.56.119:47018,172.104.56.146:47018/web_huangguo2_log?replicaSet=web_jiqun3&maxPoolSize=200&connectTimeout=30&authSource=web_huangguo2" + addr: "mongodb://web_huangguo2:xDdEkf6m0HDpkEpxpphi@172.104.52.130:27017,172.104.52.26:27017,172.104.52.242:27017/web_huangguo2?replicaSet=fish0&maxPoolSize=200&connectTimeout=30&authSource=web_huangguo2" + logaddr: "mongodb://web_huangguo2:xDdEkf6m0HDpkEpxpphi@172.104.52.130:27017,172.104.52.26:27017,172.104.52.242:27017/web_huangguo2_log?replicaSet=fish0&maxPoolSize=200&connectTimeout=30&authSource=web_huangguo2" es: addr: "http://139.162.47.194:9200" user: "elastic"