mirror of
https://github.com/snowykami/neo-blog.git
synced 2025-09-26 02:56:22 +00:00
feat: 更新评论功能,优化代码格式,添加位置格式化功能
All checks were successful
Push to Helm Chart Repository / build (push) Successful in 52s
All checks were successful
Push to Helm Chart Repository / build (push) Successful in 52s
This commit is contained in:
@ -15,6 +15,7 @@ const (
|
|||||||
EnvKeyCaptchaSecreteKey = "CAPTCHA_SECRET_KEY" // captcha站点密钥
|
EnvKeyCaptchaSecreteKey = "CAPTCHA_SECRET_KEY" // captcha站点密钥
|
||||||
EnvKeyCaptchaUrl = "CAPTCHA_URL" // 某些自托管的captcha的url
|
EnvKeyCaptchaUrl = "CAPTCHA_URL" // 某些自托管的captcha的url
|
||||||
EnvKeyCaptchaSiteKey = "CAPTCHA_SITE_KEY" // captcha密钥key
|
EnvKeyCaptchaSiteKey = "CAPTCHA_SITE_KEY" // captcha密钥key
|
||||||
|
EnvKeyLocationFormat = "LOCATION_FORMAT" // 环境变量:时区格式
|
||||||
EnvKeyLogLevel = "LOG_LEVEL" // 环境变量:日志级别
|
EnvKeyLogLevel = "LOG_LEVEL" // 环境变量:日志级别
|
||||||
EnvKeyMode = "MODE" // 环境变量:运行模式
|
EnvKeyMode = "MODE" // 环境变量:运行模式
|
||||||
EnvKeyJwtSecrete = "JWT_SECRET" // 环境变量:JWT密钥
|
EnvKeyJwtSecrete = "JWT_SECRET" // 环境变量:JWT密钥
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"text/template"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
"github.com/snowykami/neo-blog/pkg/constant"
|
||||||
)
|
)
|
||||||
|
|
||||||
type IPData struct {
|
type IPData struct {
|
||||||
@ -56,5 +59,18 @@ func GetLocationString(ip string) string {
|
|||||||
if ipInfo == nil {
|
if ipInfo == nil {
|
||||||
return ""
|
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()
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user