Skip to content

Commit

Permalink
使用metadata数据作为version,增加多路径配置文件下发
Browse files Browse the repository at this point in the history
Signed-off-by: MEX7 <mex7.0828@gmail.com>
  • Loading branch information
kl7sn committed Jul 15, 2020
1 parent 4dd73b0 commit 75d4d42
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
15 changes: 8 additions & 7 deletions pkg/proxy/confProxy/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ func (d *DataSource) watch() {
} else {
xlog.Error("watch update error", xlog.String("plugin", "confgo"), xlog.String("msg", err.Error()), xlog.String("key", key))
}
fmt.Println("==err111", err.Error())
continue
} else {
commonKey := util.GetConfigKey(confuNode.AppName, confuNode.AppEnvi, confuNode.FileName, confuNode.Port)
Expand Down Expand Up @@ -226,7 +225,7 @@ func (d *DataSource) ListenAppConfig(ctx echo.Context, key string) chan *structs
// update 更新本地文件
func (d *DataSource) update(key, value string) (*structs.ConfNode, error) {
confNode := &structs.ConfNode{}
//key check
// key check
confuKeys, err := structs.ParserConfKey(key)
if err != nil {
return confNode, err
Expand All @@ -236,7 +235,7 @@ func (d *DataSource) update(key, value string) (*structs.ConfNode, error) {
}
xlog.Debug("file update content", xlog.String("plugin", "confgo"), xlog.Any("confuKeys", confuKeys), xlog.String("key", key), xlog.String("value", value))

//value check
// value check
confuValue, err := structs.ParserConfValue(value)
if err != nil {
return confNode, err
Expand All @@ -245,9 +244,11 @@ func (d *DataSource) update(key, value string) (*structs.ConfNode, error) {
return confNode, fmt.Errorf("value check: %s", err.Error())
}

//write file
if err := util.WriteFile(confuValue.Metadata.Path, confuValue.Content); err != nil {
return confNode, err
for _, path := range confuValue.Metadata.Paths {
// write file
if err := util.WriteFile(path, confuValue.Content); err != nil {
return confNode, err
}
}

confNode = &structs.ConfNode{
Expand Down Expand Up @@ -286,7 +287,7 @@ func (d *DataSource) report(key, value string) error {
reportKey := strings.Join([]string{d.prefix + "/callback", confuKeys.AppName, confuKeys.FileName, confuKeys.Hostname}, "/")
reportValue := structs.ConfReport{
FileName: confuKeys.FileName,
MD5: util.MD5(confuValue.Content),
MD5: confuValue.Metadata.Version,
Hostname: confuKeys.Hostname,
Env: confuKeys.EnvName,
Timestamp: time.Now().Unix(),
Expand Down
20 changes: 17 additions & 3 deletions pkg/proxy/confProxy/etcd/view.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
// Copyright 2020 Douyu
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package etcd

// ConfDataSourceEtcd ETCD dataSource config
type ConfDataSourceEtcd struct {
Enable bool // 是否开启用该数据源
Secure bool
EndPoints []string `json:"endpoints"` // 注册中心etcd节点信息
Enable bool // 是否开启用该数据源
Secure bool
EndPoints []string `json:"endpoints"` // 注册中心etcd节点信息
}
8 changes: 4 additions & 4 deletions pkg/structs/conf_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ type ConfValue struct {

// MetaData ...
type MetaData struct {
Timestamp int64 `json:"timestamp"`
Version string `json:"version"`
Format string `json:"format"`
Path string `json:"path"`
Timestamp int64 `json:"timestamp"`
Version string `json:"version"`
Format string `json:"format"`
Paths []string `json:"paths"`
}

// CheckValid ...
Expand Down

0 comments on commit 75d4d42

Please sign in to comment.