- 移除 GetRedisConfig 函数- 修改 GetSecret 函数通过 HTTP 请求获取 AES 加密参数- 添加 json 和 github.com/go-resty/resty/v2依赖 - 升级多个依赖包版本,包括 lancet、excelize、go-deepcopy 等 - 更新 go.mod 和 go.sum 文件中的依赖版本 - 优化 token 服务中密钥获取错误处理逻辑
56 lines
1.0 KiB
Go
56 lines
1.0 KiB
Go
package config
|
|
|
|
import (
|
|
"encoding/json"
|
|
"github.com/go-resty/resty/v2"
|
|
"strings"
|
|
|
|
"github.com/beego/beego/v2/core/config/env"
|
|
)
|
|
|
|
type RedisConfig struct {
|
|
Host string `json:"host"`
|
|
Port int `json:"port"`
|
|
Password string `json:"password"`
|
|
DB int `json:"db"`
|
|
}
|
|
|
|
type Secret struct {
|
|
Key string `json:"key"`
|
|
IV string `json:"iv"`
|
|
}
|
|
|
|
func GetGatewayHost() (url string) {
|
|
url = env.Get("gatewayAddr", url)
|
|
if url != "" {
|
|
if !strings.HasSuffix(url, "/") {
|
|
url += "/"
|
|
}
|
|
return
|
|
}
|
|
return "http://127.0.0.1:12309/"
|
|
}
|
|
|
|
func GetPortalHost() (url string) {
|
|
url = env.Get("portalAddr", url)
|
|
if url != "" {
|
|
return
|
|
}
|
|
return "http://127.0.0.1:12400/"
|
|
}
|
|
|
|
func GetSecret() (*Secret, error) {
|
|
response, err := resty.New().R().Get("http://kami_backend:22401/api/aes/encryption/params")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
result := struct {
|
|
Code int `json:"code"`
|
|
Data Secret `json:"data"`
|
|
}{}
|
|
if err = json.Unmarshal(response.Body(), &result); err != nil {
|
|
return nil, err
|
|
}
|
|
return &result.Data, nil
|
|
}
|