Skip to content

Commit

Permalink
remove redundant options
Browse files Browse the repository at this point in the history
  • Loading branch information
Shonminh committed Feb 7, 2020
1 parent e872971 commit 9722dc3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
9 changes: 6 additions & 3 deletions examples/apollo/apollo.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
agollo "github.com/Shonminh/apollo-client"
"github.com/go-chassis/go-archaius"
"github.com/go-chassis/go-archaius/event"
"github.com/go-chassis/go-archaius/source/apollo"
_ "github.com/go-chassis/go-archaius/source/apollo"
"github.com/go-mesh/openlogging"
"time"
Expand All @@ -24,9 +25,11 @@ func (li *Listener) Event(event *event.Event) {
func main() {

err := archaius.Init(archaius.WithRemoteSource(archaius.ApolloSource, &archaius.RemoteInfo{
URL: "http://127.0.0.1:8000",
NamespaceList: "demo",
AppID: "demo-apollo",
URL: "http://127.0.0.1:8000",
DefaultDimension: map[string]string{
apollo.AppID: "demo-apollo",
apollo.NamespaceList: "demo",
},
}))
fmt.Println(err)
// register listener, key is different from which in apollo web page, it's format is like {namespace}.{apollo_key}
Expand Down
3 changes: 0 additions & 3 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ type RemoteInfo struct {
ClientType string
APIVersion string
RefreshPort string
NamespaceList string // apollo namespace list, if you disable apollo, ignore it
AppID string // apollo app id, if you disable apollo, ignore it
Cluster string // apollo cluster, if you disable apollo, ignore it
}

//Options hold options
Expand Down
14 changes: 10 additions & 4 deletions source/apollo/apollo.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ type Source struct {
const (
defaultApolloSourcePriority = 0 // default priority is 0
apolloSourceName = "ApolloConfigSource"
// AppID app id const
AppID = "app_id"
// NamespaceList namespace list const
NamespaceList = "namespace_list"
// Cluster cluster const
Cluster = "cluster"
)

var (
Expand All @@ -37,13 +43,13 @@ func NewApolloSource(remoteInfo *archaius.RemoteInfo) (source.ConfigSource, erro
as.priority = defaultApolloSourcePriority
opts := []apollo.Option{
apollo.WithApolloAddr(remoteInfo.URL),
apollo.WithAppId(remoteInfo.AppID),
apollo.WithNamespaceName(remoteInfo.NamespaceList),
apollo.WithAppId(remoteInfo.DefaultDimension[AppID]),
apollo.WithNamespaceName(remoteInfo.DefaultDimension[NamespaceList]),
apollo.WithLogFunc(openlogging.GetLogger().Debugf, openlogging.GetLogger().Infof, openlogging.GetLogger().Errorf),
}

if remoteInfo.Cluster != "" {
opts = append(opts, apollo.WithCluster(remoteInfo.Cluster))
if remoteInfo.DefaultDimension[Cluster] != "" {
opts = append(opts, apollo.WithCluster(remoteInfo.DefaultDimension[Cluster]))
}
if err := apollo.Init(opts...); err != nil {
return nil, errors.New("apollo client init failed, error=" + err.Error())
Expand Down

0 comments on commit 9722dc3

Please sign in to comment.