Skip to content

Commit 319530d

Browse files
committed
refactor for new version
1 parent 0e7984a commit 319530d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+306
-301
lines changed

agcache/memory/memory.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,15 @@ package memory
1919

2020
import (
2121
"errors"
22-
"github.com/zouyx/agollo/v3/agcache"
23-
"github.com/zouyx/agollo/v3/extension"
22+
"github.com/zouyx/agollo/v4/agcache"
2423
"sync"
2524
"sync/atomic"
2625
)
2726

28-
func init() {
29-
extension.SetCacheFactory(&DefaultCacheFactory{})
30-
}
31-
3227
//DefaultCache 默认缓存
3328
type DefaultCache struct {
3429
defaultCache sync.Map
35-
count int64
30+
count int64
3631
}
3732

3833
//Set 获取缓存

agcache/memory/memory_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"testing"
2222

2323
. "github.com/tevid/gohamcrest"
24-
"github.com/zouyx/agollo/v3/agcache"
24+
"github.com/zouyx/agollo/v4/agcache"
2525
)
2626

2727
var testDefaultCache agcache.CacheInterface

client.go

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package agollo
19+
20+
import (
21+
"github.com/zouyx/agollo/v4/agcache/memory"
22+
"github.com/zouyx/agollo/v4/cluster/roundrobin"
23+
"github.com/zouyx/agollo/v4/component"
24+
"github.com/zouyx/agollo/v4/component/log"
25+
"github.com/zouyx/agollo/v4/component/notify"
26+
"github.com/zouyx/agollo/v4/component/serverlist"
27+
"github.com/zouyx/agollo/v4/env"
28+
"github.com/zouyx/agollo/v4/env/config"
29+
jsonFile "github.com/zouyx/agollo/v4/env/file/json"
30+
"github.com/zouyx/agollo/v4/extension"
31+
"github.com/zouyx/agollo/v4/protocol/auth/sign"
32+
"github.com/zouyx/agollo/v4/storage"
33+
)
34+
35+
type Client struct {
36+
initAppConfigFunc func() (*config.AppConfig, error)
37+
}
38+
39+
func Create() *Client {
40+
extension.SetCacheFactory(&memory.DefaultCacheFactory{})
41+
extension.SetLoadBalance(&roundrobin.RoundRobin{})
42+
extension.SetFileHandler(&jsonFile.FileHandler{})
43+
extension.SetHTTPAuth(&sign.AuthSignature{})
44+
storage.InitConfigCache()
45+
return &Client{}
46+
}
47+
48+
func (c *Client) Start() error {
49+
return c.StartWithConfig(nil)
50+
}
51+
52+
func (c *Client) StartWithConfig(loadAppConfig func() (*config.AppConfig, error)) error {
53+
// 有了配置之后才能进行初始化
54+
if err := env.InitConfig(loadAppConfig); err != nil {
55+
return err
56+
}
57+
58+
notify.InitAllNotifications(nil)
59+
serverlist.InitSyncServerIPList()
60+
61+
//first sync
62+
if err := notify.SyncConfigs(); err != nil {
63+
return err
64+
}
65+
log.Debug("init notifySyncConfigServices finished")
66+
67+
//start long poll sync config
68+
go component.StartRefreshConfig(&notify.ConfigComponent{})
69+
70+
log.Info("agollo start finished ! ")
71+
72+
return nil
73+
}

cluster/load_balance.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ package cluster
2020
import (
2121
"sync"
2222

23-
"github.com/zouyx/agollo/v3/env/config"
23+
"github.com/zouyx/agollo/v4/env/config"
2424
)
2525

2626
//LoadBalance 负载均衡器

cluster/roundrobin/round_robin.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,9 @@ package roundrobin
2020
import (
2121
"sync"
2222

23-
"github.com/zouyx/agollo/v3/env/config"
24-
"github.com/zouyx/agollo/v3/extension"
23+
"github.com/zouyx/agollo/v4/env/config"
2524
)
2625

27-
func init() {
28-
extension.SetLoadBalance(&RoundRobin{})
29-
}
30-
3126
//RoundRobin 轮询调度
3227
type RoundRobin struct {
3328
}

cluster/roundrobin/round_robin_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"testing"
2222

2323
. "github.com/tevid/gohamcrest"
24-
"github.com/zouyx/agollo/v3/env"
24+
"github.com/zouyx/agollo/v4/env"
2525
)
2626

2727
const servicesConfigResponseStr = `[{

component/common.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ import (
2121
"fmt"
2222
"net/url"
2323

24-
"github.com/zouyx/agollo/v3/env"
25-
"github.com/zouyx/agollo/v3/env/config"
26-
"github.com/zouyx/agollo/v3/utils"
24+
"github.com/zouyx/agollo/v4/env"
25+
"github.com/zouyx/agollo/v4/env/config"
26+
"github.com/zouyx/agollo/v4/utils"
2727
)
2828

2929
//AbsComponent 定时组件

component/common_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ import (
2121
"testing"
2222

2323
. "github.com/tevid/gohamcrest"
24-
_ "github.com/zouyx/agollo/v3/cluster/roundrobin"
25-
"github.com/zouyx/agollo/v3/env"
26-
"github.com/zouyx/agollo/v3/env/config"
27-
"github.com/zouyx/agollo/v3/env/config/json"
28-
"github.com/zouyx/agollo/v3/extension"
24+
_ "github.com/zouyx/agollo/v4/cluster/roundrobin"
25+
"github.com/zouyx/agollo/v4/env"
26+
"github.com/zouyx/agollo/v4/env/config"
27+
"github.com/zouyx/agollo/v4/env/config/json"
28+
"github.com/zouyx/agollo/v4/extension"
2929
)
3030

3131
const servicesConfigResponseStr = `[{

component/notify/change_event_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ import (
2525
"time"
2626

2727
. "github.com/tevid/gohamcrest"
28-
_ "github.com/zouyx/agollo/v3/agcache/memory"
29-
"github.com/zouyx/agollo/v3/env"
30-
_ "github.com/zouyx/agollo/v3/env/file/json"
31-
"github.com/zouyx/agollo/v3/storage"
28+
_ "github.com/zouyx/agollo/v4/agcache/memory"
29+
"github.com/zouyx/agollo/v4/env"
30+
_ "github.com/zouyx/agollo/v4/env/file/json"
31+
"github.com/zouyx/agollo/v4/storage"
3232
)
3333

3434
type CustomChangeListener struct {

component/notify/componet_notify.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,20 @@ package notify
2020
import (
2121
"encoding/json"
2222
"fmt"
23-
"github.com/zouyx/agollo/v3/constant"
23+
"github.com/zouyx/agollo/v4/constant"
2424
"net/url"
2525
"path"
2626
"sync"
2727
"time"
2828

29-
"github.com/zouyx/agollo/v3/component"
30-
"github.com/zouyx/agollo/v3/component/log"
31-
"github.com/zouyx/agollo/v3/env"
32-
"github.com/zouyx/agollo/v3/env/config"
33-
"github.com/zouyx/agollo/v3/extension"
34-
"github.com/zouyx/agollo/v3/protocol/http"
35-
"github.com/zouyx/agollo/v3/storage"
36-
"github.com/zouyx/agollo/v3/utils"
29+
"github.com/zouyx/agollo/v4/component"
30+
"github.com/zouyx/agollo/v4/component/log"
31+
"github.com/zouyx/agollo/v4/env"
32+
"github.com/zouyx/agollo/v4/env/config"
33+
"github.com/zouyx/agollo/v4/extension"
34+
"github.com/zouyx/agollo/v4/protocol/http"
35+
"github.com/zouyx/agollo/v4/storage"
36+
"github.com/zouyx/agollo/v4/utils"
3737
)
3838

3939
const (

component/notify/componet_notify_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ import (
2727
"time"
2828

2929
. "github.com/tevid/gohamcrest"
30-
_ "github.com/zouyx/agollo/v3/cluster/roundrobin"
31-
"github.com/zouyx/agollo/v3/env"
32-
"github.com/zouyx/agollo/v3/env/config"
33-
jsonConfig "github.com/zouyx/agollo/v3/env/config/json"
34-
_ "github.com/zouyx/agollo/v3/env/file/json"
35-
"github.com/zouyx/agollo/v3/extension"
30+
_ "github.com/zouyx/agollo/v4/cluster/roundrobin"
31+
"github.com/zouyx/agollo/v4/env"
32+
"github.com/zouyx/agollo/v4/env/config"
33+
jsonConfig "github.com/zouyx/agollo/v4/env/config/json"
34+
_ "github.com/zouyx/agollo/v4/env/file/json"
35+
"github.com/zouyx/agollo/v4/extension"
3636
)
3737

3838
var (

component/notify/config_server_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"strings"
2525
"time"
2626

27-
"github.com/zouyx/agollo/v3/env"
27+
"github.com/zouyx/agollo/v4/env"
2828
)
2929

3030
const configResponseStr = `{

component/serverlist/sync.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ package serverlist
2020
import (
2121
"time"
2222

23-
"github.com/zouyx/agollo/v3/component"
24-
"github.com/zouyx/agollo/v3/component/log"
25-
"github.com/zouyx/agollo/v3/env"
26-
"github.com/zouyx/agollo/v3/env/config"
27-
"github.com/zouyx/agollo/v3/protocol/http"
23+
"github.com/zouyx/agollo/v4/component"
24+
"github.com/zouyx/agollo/v4/component/log"
25+
"github.com/zouyx/agollo/v4/env"
26+
"github.com/zouyx/agollo/v4/env/config"
27+
"github.com/zouyx/agollo/v4/protocol/http"
2828
)
2929

3030
const (

component/serverlist/sync_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import (
2121
"testing"
2222

2323
. "github.com/tevid/gohamcrest"
24-
"github.com/zouyx/agollo/v3/env"
25-
"github.com/zouyx/agollo/v3/env/config"
24+
"github.com/zouyx/agollo/v4/env"
25+
"github.com/zouyx/agollo/v4/env/config"
2626
)
2727

2828
func TestSyncServerIPList(t *testing.T) {

env/apollo_config.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ package env
2020
import (
2121
"sync"
2222

23-
"github.com/zouyx/agollo/v3/utils"
23+
"github.com/zouyx/agollo/v4/utils"
2424
)
2525

2626
var (
@@ -77,11 +77,9 @@ type ApolloConfig struct {
7777
Configurations map[string]interface{} `json:"configurations"`
7878
}
7979

80-
8180
//Init 初始化
8281
func (a *ApolloConfig) Init(appID string, cluster string, namespace string) {
8382
a.AppID = appID
8483
a.Cluster = cluster
8584
a.NamespaceName = namespace
8685
}
87-

env/apollo_config_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"testing"
2222

2323
. "github.com/tevid/gohamcrest"
24-
"github.com/zouyx/agollo/v3/utils"
24+
"github.com/zouyx/agollo/v4/utils"
2525
)
2626

2727
func TestSetCurrentApolloConfig(t *testing.T) {

0 commit comments

Comments
 (0)