Skip to content

Commit

Permalink
Merge pull request #2 from xurwxj/nzg_cumx
Browse files Browse the repository at this point in the history
mv remoteconfig
  • Loading branch information
qiannianshaonian authored Nov 3, 2021
2 parents b9ea2c1 + ca94705 commit 5d73217
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 130 deletions.
23 changes: 21 additions & 2 deletions registry/refreshConfig.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package registry

import (
"bytes"
"encoding/base64"
"encoding/json"
"io/ioutil"
"net/http"
"os"

"github.com/smallnest/rpcx/log"
"github.com/soheilhy/cmux"
"github.com/xurwxj/gtils/base"
"github.com/xurwxj/rpcx_consul/remoteconfig"
"github.com/xurwxj/viper"
)

type CmuxPluginConfig struct {
Expand Down Expand Up @@ -41,7 +43,7 @@ func (s *CmuxPluginConfig) MuxMatch(m cmux.CMux) {
if len(c) > 0 {
v := c[0].Value
newValue, _ := base64.StdEncoding.DecodeString(v)
remoteconfig.MergeConfig(string(newValue))
MergeConfig(string(newValue))
log.Debugf("consulConfigUpdate kvKey=%v value=%v ", c[0].Key, string(newValue))
}
resByte, err := base.GetByteArrayFromInterface(map[string]interface{}{
Expand All @@ -63,3 +65,20 @@ func (s *CmuxPluginConfig) MuxMatch(m cmux.CMux) {
}
go httpS.Serve(listener)
}

func MergeConfig(data string) {
if data == "" {
return
}
base.CheckPathExistOrCreate("nacos")
err := os.WriteFile("nacos/remote.json", []byte(data), os.ModePerm)
if err != nil {
log.Errorf("mergeConfig:WriteFile config=%v err=%v ", data, err)
}
err = viper.MergeConfig(bytes.NewReader([]byte(data)))
if err != nil {
log.Errorf("mergeConfig config=%v err=%v ", data, err)
} else {
log.Infof("mergeConfig done success ")
}
}
64 changes: 0 additions & 64 deletions remoteconfig/consul.go

This file was deleted.

64 changes: 0 additions & 64 deletions remoteconfig/index.go

This file was deleted.

0 comments on commit 5d73217

Please sign in to comment.