Skip to content

Commit

Permalink
migrate go-chassis-config into archaius project (#87)
Browse files Browse the repository at this point in the history
* add go sum

* update config, add sum

* migrate go-chassis-config into archaius project
  • Loading branch information
tianxiaoliang authored Dec 3, 2019
1 parent 33fbf46 commit 6963ff7
Show file tree
Hide file tree
Showing 27 changed files with 1,213 additions and 65 deletions.
6 changes: 2 additions & 4 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
go-chassis Go Archaius
Copyright 2019-present, tianxiaoliang

This product includes software developed at
go archaius
Copyright 2017-2019 Huawei Technologies Co.,Ltd.

====================================================================
For core/cast/cast.go (Forked from github.com/spf13/cast)
Expand Down
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ below example also enables env and mem sources.
```

### Put value into archaius
Notice, key value will be only put into memory source, it could be overwritten by remote config
Notice, key value will be only put into memory source, it could be overwritten by remote config as the precedence list
```go
archaius.Set("interval", 30)
archaius.Set("ttl", "30s")
Expand Down Expand Up @@ -109,15 +109,15 @@ v := archaius.GetString("/etc/component/xxx.txt", "")
### Enable remote source
import a config client implementation
```go
import _ "github.com/go-chassis/go-chassis-config/servicecomb"
import _ "github.com/go-chassis/go-archaius/source/remote/configcenter"
```
set config client to init config center source
```go
ci := archaius.RemoteInfo{
//input your remote source config
}
//create config client
cc,_:=ccclient.NewClient("servicecomb-kie",ccclient.Options{
cc,_:=remote.NewClient("config_center",ccclient.Options{
ServerURI:"the address of config server endpoint",
})
//manage local and remote key value at same time
Expand All @@ -128,8 +128,12 @@ set config client to init config center source
)
```

To check config server that archaius supports,
access https://github.com/go-chassis/go-chassis-config
Supported distributed configuration management service:

| name | import |description |
|----------|----------|:-------------:|
|config_center |github.com/go-chassis/go-chassis-config/configcenter |huawei cloud CSE config center https://www.huaweicloud.com/product/cse.html |
|servicecomb-kie |github.com/apache/servicecomb-kie/client/adaptor |apache servicecomb-kie https://github.com/apache/servicecomb-kie |

### Example: Manage local configurations
Complete [example](https://github.com/go-chassis/go-archaius/tree/master/examples/file)
Expand Down
7 changes: 3 additions & 4 deletions archaius.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/go-chassis/go-archaius/source/file"
"github.com/go-chassis/go-archaius/source/mem"
"github.com/go-chassis/go-archaius/source/remote"
"github.com/go-chassis/go-chassis-config"
"github.com/go-mesh/openlogging"
)

Expand Down Expand Up @@ -119,7 +118,7 @@ func CustomInit(sources ...source.ConfigSource) error {
//EnableRemoteSource create a remote source singleton
//A config center source pull remote config server key values into local memory
//so that you can use GetXXX to get value easily
func EnableRemoteSource(ci *RemoteInfo, cc config.Client) error {
func EnableRemoteSource(ci *RemoteInfo, cc remote.Client) error {
if ci == nil {
return errors.New("RemoteInfo can not be empty")
}
Expand All @@ -130,7 +129,7 @@ func EnableRemoteSource(ci *RemoteInfo, cc config.Client) error {

var err error
if cc == nil {
opts := config.Options{
opts := remote.Options{
ServerURI: ci.URL,
TenantName: ci.TenantName,
EnableSSL: ci.EnableSSL,
Expand All @@ -139,7 +138,7 @@ func EnableRemoteSource(ci *RemoteInfo, cc config.Client) error {
AutoDiscovery: ci.AutoDiscovery,
Labels: ci.DefaultDimension,
}
cc, err = config.NewClient(ci.ClientType, opts)
cc, err = remote.NewClient(ci.ClientType, opts)
if err != nil {
return err
}
Expand Down
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ module github.com/go-chassis/go-archaius

require (
github.com/fsnotify/fsnotify v1.4.7
github.com/go-chassis/go-chassis-config v0.14.0
github.com/go-chassis/foundation v0.1.1-0.20191113114104-2b05871e9ec4
github.com/go-mesh/openlogging v1.0.1
github.com/gorilla/websocket v1.4.0
github.com/spf13/cast v1.2.0
github.com/stretchr/testify v1.3.0
golang.org/x/sys v0.0.0-20191018095205-727590c5006e // indirect
gopkg.in/yaml.v2 v2.2.1
)

go 1.13
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/go-chassis/foundation v0.0.0-20190621030543-c3b63f787f4c h1:p+Y6yq7RwHmYjEr/vwdVYGacBqFCc2lPQfNRIC3vRIs=
github.com/go-chassis/foundation v0.0.0-20190621030543-c3b63f787f4c/go.mod h1:21/ajGtgJlWTCeM0TxGJdRhO8bJkKirWyV8Stlh6g6c=
github.com/go-chassis/foundation v0.1.1-0.20191113114104-2b05871e9ec4 h1:wx8JXvg/n4i8acXsBJ5zIkiK7EO2kn/HuEjKK3kSgv8=
github.com/go-chassis/foundation v0.1.1-0.20191113114104-2b05871e9ec4/go.mod h1:21/ajGtgJlWTCeM0TxGJdRhO8bJkKirWyV8Stlh6g6c=
github.com/go-chassis/go-chassis-config v0.14.0 h1:OnM9sx2GalDC7vEIhPecRpQlVa8hz10NOB41+9tii5A=
github.com/go-chassis/go-chassis-config v0.14.0/go.mod h1:qzvK/aoAv0O/khmF6ehW6RgELrF1JR2F555T9izoo2A=
github.com/go-mesh/openlogging v1.0.1 h1:6raaXo8SK+wuQX1VoNi6QJCSf1fTOFWh7f5f6b2ZEmY=
github.com/go-mesh/openlogging v1.0.1/go.mod h1:qaKi+amO+hsGin2q1GmW+/NcbZpMPnTufwrWzDmIuuU=
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down
7 changes: 3 additions & 4 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package archaius

import (
"crypto/tls"
"github.com/go-chassis/go-archaius/source/remote"
"github.com/go-chassis/go-archaius/source/util"

"github.com/go-chassis/go-chassis-config"
)

// RemoteInfo has attribute for config center source initialization
Expand Down Expand Up @@ -42,7 +41,7 @@ type Options struct {
OptionalFiles []string
FileHandler util.FileHandler
RemoteInfo *RemoteInfo
ConfigClient config.Client
ConfigClient remote.Client
UseCLISource bool
UseENVSource bool
UseMemSource bool
Expand Down Expand Up @@ -77,7 +76,7 @@ func WithDefaultFileHandler(handler util.FileHandler) Option {
//RemoteInfo is required if you want to use config center source
//client is optional,if client is nil, archaius will create one based on RemoteInfo
//config client will be injected into config source as a client to interact with a config server
func WithRemoteSource(ri *RemoteInfo, c config.Client) Option {
func WithRemoteSource(ri *RemoteInfo, c remote.Client) Option {
return func(options *Options) {
options.RemoteInfo = ri
options.ConfigClient = c
Expand Down
Loading

0 comments on commit 6963ff7

Please sign in to comment.