Merge branch 'develop' into feature/mhw-v1.01

This commit is contained in:
laodaming
2023-09-20 13:57:38 +08:00
82 changed files with 195 additions and 1267 deletions

View File

@@ -10,6 +10,7 @@ import (
"github.com/nacos-group/nacos-sdk-go/v2/clients"
"github.com/nacos-group/nacos-sdk-go/v2/common/constant"
"github.com/nacos-group/nacos-sdk-go/v2/vo"
"github.com/zeromicro/go-zero/core/conf"
"gopkg.in/yaml.v2"
)
@@ -20,6 +21,15 @@ type EnvConfig struct {
NamespaceId string `yaml:"namespace"`
DataId string `yaml:"dataid"`
Group string `yaml:"group"`
ProxyServer struct {
KeyFile string `yaml:"key"`
PemFile string `yaml:"pem"`
} `yaml:"proxyserver"`
ServerBackend struct {
KeyFile string `yaml:"key"`
PemFile string `yaml:"pem"`
} `yaml:"serverbackend"`
}
var optPathDirs = []string{"/opt", "./", "../", "../../"}
@@ -63,7 +73,7 @@ func init() {
}
func StartNacosConfig(configFile string, OnChange func(namespace, group, dataId, data string)) string {
func StartNacosConfig(configFile string, cfg any, OnChange func(namespace, group, dataId, data string)) {
env := GetEnvCofing()
// 创建serverConfig
@@ -136,9 +146,40 @@ func StartNacosConfig(configFile string, OnChange func(namespace, group, dataId,
log.Fatalf("Failed to get config from Nacos: %v", err)
}
log.Println("加载成功:", cfgYaml)
var selfConfig map[string]interface{} = make(map[string]interface{})
err = yaml.Unmarshal([]byte(content), &selfConfig)
if err != nil {
log.Fatalf("Failed to get config from Nacos: %v", err)
}
return content
content, err = configClient.GetConfig(vo.ConfigParam{
DataId: "common",
Group: env.Group,
OnChange: nil,
})
if err != nil {
log.Fatalf("Failed to get config from Nacos: %v", err)
}
var commonConfig map[string]interface{} = make(map[string]interface{})
err = yaml.Unmarshal([]byte(content), &commonConfig)
if err != nil {
log.Fatalf("Failed to get config from Nacos: %v", err)
}
for k, v := range commonConfig {
selfConfig[k] = v
}
data, err := yaml.Marshal(selfConfig)
if err != nil {
log.Fatalf("Failed to get config from Nacos: %v", err)
}
log.Print("加载成功: ", cfgYaml, "\n环境: ", env.Group, "\n", string(data))
err = conf.LoadFromYamlBytes(data, cfg)
if err != nil {
log.Fatalf("Failed to get config content from Nacos: %v", err)
}
// log.Println(content)
}

View File

@@ -3,8 +3,33 @@ package fsconfig_test
import (
"fusenapi/utils/fsconfig"
"testing"
"github.com/zeromicro/go-zero/rest"
)
func TestCase1(t *testing.T) {
fsconfig.StartNacosConfig("auth.yaml", nil)
type Config struct {
rest.RestConf
SourceMysql string
ReplicaId uint64
MainAddress string
WebsocketAddr string
OAuth struct {
Google struct {
Appid string
Secret string
}
Facebook struct {
Appid string
Secret string
}
}
}
func TestCase1(t *testing.T) {
var c Config
fsconfig.StartNacosConfig("auth.yaml", &c, nil)
}

View File

@@ -10,9 +10,8 @@ type DataTransferData struct {
// websocket接受要云渲染处理的数据
type RenderImageReqMsg struct {
RenderId string `json:"render_id"` //渲染id
OnlyReturnCombineImage bool `json:"only_return_combine_image"` //是否只返回刀版图
RenderData RenderData `json:"render_data"`
RenderId string `json:"render_id"` //渲染id
RenderData RenderData `json:"render_data"` //渲染主要参数
}
type RenderData struct {
TemplateTag string `json:"template_tag"` //模板标签(必须)
@@ -25,7 +24,6 @@ type RenderData struct {
Address string `json:"address"` //地址(可选)
Phone string `json:"phone"` //电话(可选)
Qrcode string `json:"qrcode"` //二维码(可选)
ProductSizeId int64 `json:"product_size_id"` //尺寸id(可选)
UserId int64 `json:"user_id"` //用户id(websocket连接建立再赋值)
GuestId int64 `json:"guest_id"` //游客id(websocket连接建立再赋值)
}