Skip to content

Commit

Permalink
Finish v4.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
zouyx committed Nov 13, 2020
2 parents 30024a3 + 047e235 commit bf8c0b4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
24 changes: 13 additions & 11 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,7 @@ import (
"strconv"
)

var syncApolloConfig = remote.CreateSyncApolloConfig()

// Client apollo 客户端实例
type Client struct {
initAppConfigFunc func() (*config.AppConfig, error)
appConfig *config.AppConfig
cache *storage.Cache
}

func create() *Client {
func init() {
extension.SetCacheFactory(&memory.DefaultCacheFactory{})
extension.SetLoadBalance(&roundrobin.RoundRobin{})
extension.SetFileHandler(&jsonFile.FileHandler{})
Expand All @@ -62,9 +53,20 @@ func create() *Client {
extension.AddFormatParser(constant.Properties, &properties.Parser{})
extension.AddFormatParser(constant.YML, &yml.Parser{})
extension.AddFormatParser(constant.YAML, &yaml.Parser{})
}

appConfig := env.InitFileConfig()
var syncApolloConfig = remote.CreateSyncApolloConfig()

// Client apollo 客户端实例
type Client struct {
initAppConfigFunc func() (*config.AppConfig, error)
appConfig *config.AppConfig
cache *storage.Cache
}

func create() *Client {

appConfig := env.InitFileConfig()
return &Client{
appConfig: appConfig,
}
Expand Down
5 changes: 5 additions & 0 deletions env/file/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"encoding/json"
"fmt"
"github.com/zouyx/agollo/v4/env/config"
"sync"

"github.com/zouyx/agollo/v4/component/log"
jsonConfig "github.com/zouyx/agollo/v4/env/config/json"
Expand All @@ -35,6 +36,8 @@ var (
jsonFileConfig = &jsonConfig.ConfigFile{}
//configFileMap 存取namespace文件地址
configFileMap = make(map[string]string, 1)
//configFileMapLock configFileMap的读取锁
configFileMapLock sync.Mutex
)

// FileHandler 默认备份文件读写
Expand All @@ -49,6 +52,8 @@ func (fileHandler *FileHandler) WriteConfigFile(config *config.ApolloConfig, con
// GetConfigFile get real config file
func (fileHandler *FileHandler) GetConfigFile(configDir string, appID string, namespace string) string {
key := fmt.Sprintf("%s-%s", appID, namespace)
configFileMapLock.Lock()
defer configFileMapLock.Unlock()
fullPath := configFileMap[key]
if fullPath == "" {
filePath := fmt.Sprintf("%s%s", key, Suffix)
Expand Down

0 comments on commit bf8c0b4

Please sign in to comment.