feat: 更新评论功能,优化代码格式,添加位置格式化功能
All checks were successful
Push to Helm Chart Repository / build (push) Successful in 52s

This commit is contained in:
2025-09-13 16:55:58 +08:00
parent 4da06b931f
commit 8be05cd9c2
4 changed files with 244 additions and 227 deletions

View File

@ -15,6 +15,7 @@ const (
EnvKeyCaptchaSecreteKey = "CAPTCHA_SECRET_KEY" // captcha站点密钥
EnvKeyCaptchaUrl = "CAPTCHA_URL" // 某些自托管的captcha的url
EnvKeyCaptchaSiteKey = "CAPTCHA_SITE_KEY" // captcha密钥key
EnvKeyLocationFormat = "LOCATION_FORMAT" // 环境变量:时区格式
EnvKeyLogLevel = "LOG_LEVEL" // 环境变量:日志级别
EnvKeyMode = "MODE" // 环境变量:运行模式
EnvKeyJwtSecrete = "JWT_SECRET" // 环境变量JWT密钥

View File

@ -1,9 +1,12 @@
package utils
import (
"bytes"
"fmt"
"text/template"
"github.com/sirupsen/logrus"
"github.com/snowykami/neo-blog/pkg/constant"
)
type IPData struct {
@ -56,5 +59,18 @@ func GetLocationString(ip string) string {
if ipInfo == nil {
return ""
}
return fmt.Sprintf("%s %s %s %s", ipInfo.Country, ipInfo.Province, ipInfo.City, ipInfo.ISP)
tpl := Env.Get(constant.EnvKeyLocationFormat, "{{.Country}} {{.Province}} {{.City}} {{.ISP}}")
t, err := template.New("location").Parse(tpl)
if err != nil {
logrus.Error(err)
return ""
}
var buf bytes.Buffer
if err := t.Execute(&buf, ipInfo); err != nil {
logrus.Error(err)
return ""
}
return buf.String()
}