Skip to content

Commit

Permalink
Finish v4.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
zouyx committed May 9, 2021
2 parents 08e15f2 + 6d61786 commit 3cf5cd9
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 39 deletions.
13 changes: 0 additions & 13 deletions .dependabot/config.yml

This file was deleted.

14 changes: 14 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: 2
updates:
- package-ecosystem: gomod
directory: "/"
schedule:
interval: daily
time: "21:00"
open-pull-requests-limit: 10
target-branch: develop
assignees:
- zouyx
labels:
- dependencies
- dependabot
36 changes: 21 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,27 @@ Agollo - Go Client for Apollo
方便Golang接入配置中心框架 [Apollo](https://github.com/ctripcorp/apollo) 所开发的Golang版本客户端。

# Features

* 支持多 IP、AppID、namespace
* 实时同步配置
* 灰度配置
* 延迟加载(运行时)namespace
* 客户端,配置文件容灾
* 自定义日志,缓存组件
* 支持配置访问秘钥

# Usage

## 快速入门

### 导入 agollo

```
go get -u github.com/zouyx/agollo/v4@latest
```

### 启动 agollo

```
package main
Expand All @@ -41,50 +44,53 @@ import (
"github.com/zouyx/agollo/v4/env/config"
)
func main(){
c := &config.AppConfig{
func main() {
c := &config.AppConfig{
AppID: "testApplication_yang",
Cluster: "dev",
IP: "http://106.54.227.205:8080",
NamespaceName: "dubbo",
IsBackupConfig: true,
Secret: "6ce3ff7e96a24335a9634fe9abca6d51",
}
agollo.SetLogger(&DefaultLogger{})
client,err:=agollo.StartWithConfig(func() (*config.AppConfig, error) {
client, err := agollo.StartWithConfig(func() (*config.AppConfig, error) {
return c, nil
})
fmt.Println("初始化Apollo配置成功")
//Use your apollo key to test
cache := client.GetConfigCache(c.NamespaceName)
value,_ := client.Get("key")
fmt.Println(value)
fmt.Println("初始化Apollo配置成功")
//Use your apollo key to test
cache := client.GetConfigCache(c.NamespaceName)
value, _ := client.Get("key")
fmt.Println(value)
}
```


## 更多用法

***使用Demo***[agollo_demo](https://github.com/zouyx/agollo_demo)

***其他语言***[agollo-agent](https://github.com/zouyx/agollo-agent.git) 做本地agent接入,如:PHP

欢迎查阅 [Wiki](https://github.com/zouyx/agollo/wiki) 或者 [godoc](http://godoc.org/github.com/zouyx/agollo) 获取更多有用的信息

如果你觉得该工具还不错或者有问题,一定要让我知道,可以发邮件或者[留言](https://github.com/zouyx/agollo/issues)

# User

* [使用者名单](https://github.com/zouyx/agollo/issues/20)

# Contribution
* Source Code: https://github.com/zouyx/agollo/
* Issue Tracker: https://github.com/zouyx/agollo/issues


* Source Code: https://github.com/zouyx/agollo/
* Issue Tracker: https://github.com/zouyx/agollo/issues

# License

The project is licensed under the [Apache 2 license](https://github.com/zouyx/agollo/blob/master/LICENSE).

# Reference

Apollo : https://github.com/ctripcorp/apollo
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func StartWithConfig(loadAppConfig func() (*config.AppConfig, error)) (*Client,
configs := syncApolloConfig.Sync(c.getAppConfig)
if len(configs) > 0 {
for _, apolloConfig := range configs {
c.cache.UpdateApolloConfig(apolloConfig, c.getAppConfig, true)
c.cache.UpdateApolloConfig(apolloConfig, c.getAppConfig)
}
}

Expand Down
2 changes: 1 addition & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func TestAutoSyncConfigServicesNormal2NotModified(t *testing.T) {
apolloConfig, _ := createApolloConfigWithJSON([]byte(configResponseStr))
client.cache.UpdateApolloConfig(apolloConfig.(*config.ApolloConfig), func() config.AppConfig {
return *newAppConfig
}, true)
})

config := newAppConfig.GetCurrentApolloConfig().Get()[newAppConfig.NamespaceName]

Expand Down
2 changes: 1 addition & 1 deletion component/notify/componet_notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (c *ConfigComponent) Start() {
case <-t2.C:
configs := instance.Sync(c.appConfigFunc)
for _, apolloConfig := range configs {
c.cache.UpdateApolloConfig(apolloConfig, c.appConfigFunc, true)
c.cache.UpdateApolloConfig(apolloConfig, c.appConfigFunc)
}
t2.Reset(longPollInterval)
}
Expand Down
8 changes: 4 additions & 4 deletions protocol/http/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func Request(requestURL string, connectionConfig *env.ConnectConfig, callBack *C
}
req, err := http.NewRequest("GET", requestURL, nil)
if req == nil || err != nil {
log.Error("Generate connect Apollo request Fail,url:%s,Error:%s", requestURL, err)
log.Errorf("Generate connect Apollo request Fail,url:%s,Error:%s", requestURL, err)
// if error then sleep
return nil, errors.New("generate connect Apollo request fail")
}
Expand All @@ -124,7 +124,7 @@ func Request(requestURL string, connectionConfig *env.ConnectConfig, callBack *C
}

if res == nil || err != nil {
log.Error("Connect Apollo Server Fail,url:%s,Error:%s", requestURL, err)
log.Errorf("Connect Apollo Server Fail,url:%s,Error:%s", requestURL, err)
// if error then sleep
time.Sleep(onErrorRetryInterval)
continue
Expand All @@ -135,7 +135,7 @@ func Request(requestURL string, connectionConfig *env.ConnectConfig, callBack *C
case http.StatusOK:
responseBody, err := ioutil.ReadAll(res.Body)
if err != nil {
log.Error("Connect Apollo Server Fail,url:%s,Error:", requestURL, err)
log.Errorf("Connect Apollo Server Fail,url:%s,Error:", requestURL, err)
// if error then sleep
time.Sleep(onErrorRetryInterval)
continue
Expand All @@ -152,7 +152,7 @@ func Request(requestURL string, connectionConfig *env.ConnectConfig, callBack *C
}
return nil, nil
default:
log.Error("Connect Apollo Server Fail,url:%s,StatusCode:%s", requestURL, res.StatusCode)
log.Errorf("Connect Apollo Server Fail,url:%s,StatusCode:%s", requestURL, res.StatusCode)
// if error then sleep
time.Sleep(onErrorRetryInterval)
continue
Expand Down
4 changes: 2 additions & 2 deletions storage/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func (c *Config) GetBoolValue(key string, defaultValue bool) bool {

//UpdateApolloConfig 根据config server返回的内容更新内存
//并判断是否需要写备份文件
func (c *Cache) UpdateApolloConfig(apolloConfig *config.ApolloConfig, appConfigFunc func() config.AppConfig, isBackupConfig bool) {
func (c *Cache) UpdateApolloConfig(apolloConfig *config.ApolloConfig, appConfigFunc func() config.AppConfig) {
if apolloConfig == nil {
log.Error("apolloConfig is null,can't update!")
return
Expand All @@ -246,7 +246,7 @@ func (c *Cache) UpdateApolloConfig(apolloConfig *config.ApolloConfig, appConfigF
c.pushChangeEvent(event)
}

if isBackupConfig {
if appConfig.GetIsBackupConfig() {
//write config file async
apolloConfig.AppID = appConfig.AppID
go extension.GetFileHandler().WriteConfigFile(apolloConfig, appConfig.GetBackupConfigPath())
Expand Down
4 changes: 2 additions & 2 deletions storage/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func creatTestApolloConfig(configurations map[string]interface{}, namespace stri
apolloConfig.Configurations = configurations
c.UpdateApolloConfig(apolloConfig, func() config.AppConfig {
return *appConfig
}, true)
})
return c

}
Expand All @@ -75,7 +75,7 @@ func TestUpdateApolloConfigNull(t *testing.T) {
apolloConfig.Configurations = configurations
c.UpdateApolloConfig(apolloConfig, func() config.AppConfig {
return *appConfig
}, true)
})

currentConnApolloConfig := appConfig.GetCurrentApolloConfig().Get()
config := currentConnApolloConfig[defaultNamespace]
Expand Down

0 comments on commit 3cf5cd9

Please sign in to comment.