-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ca9b5c
commit 6df6b41
Showing
9 changed files
with
1,213 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module github.com/polarismesh/polaris-go-configuration | ||
|
||
go 1.17 | ||
|
||
require github.com/polarismesh/polaris-go v1.4.3 | ||
|
||
require ( | ||
github.com/beorn7/perks v1.0.1 // indirect | ||
github.com/cespare/xxhash/v2 v2.1.2 // indirect | ||
github.com/dlclark/regexp2 v1.7.0 // indirect | ||
github.com/golang/protobuf v1.5.2 // indirect | ||
github.com/google/uuid v1.3.0 // indirect | ||
github.com/hashicorp/errwrap v1.1.0 // indirect | ||
github.com/hashicorp/go-multierror v1.1.1 // indirect | ||
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect | ||
github.com/mitchellh/go-homedir v1.1.0 // indirect | ||
github.com/modern-go/reflect2 v1.0.2 // indirect | ||
github.com/natefinch/lumberjack v2.0.0+incompatible // indirect | ||
github.com/pkg/errors v0.9.1 // indirect | ||
github.com/polarismesh/specification v1.4.0 // indirect | ||
github.com/prometheus/client_golang v1.12.2 // indirect | ||
github.com/prometheus/client_model v0.2.0 // indirect | ||
github.com/prometheus/common v0.32.1 // indirect | ||
github.com/prometheus/procfs v0.7.3 // indirect | ||
github.com/spaolacci/murmur3 v1.1.0 // indirect | ||
go.uber.org/atomic v1.10.0 // indirect | ||
go.uber.org/multierr v1.8.0 // indirect | ||
go.uber.org/zap v1.21.0 // indirect | ||
golang.org/x/net v0.2.0 // indirect | ||
golang.org/x/sys v0.2.0 // indirect | ||
golang.org/x/text v0.4.0 // indirect | ||
google.golang.org/genproto v0.0.0-20221014213838-99cd37c6964a // indirect | ||
google.golang.org/grpc v1.51.0 // indirect | ||
google.golang.org/protobuf v1.28.1 // indirect | ||
gopkg.in/yaml.v2 v2.4.0 // indirect | ||
) | ||
|
||
replace github.com/polarismesh/polaris-go => ../../../ |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* Tencent is pleased to support the open source community by making polaris-go available. | ||
* | ||
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. | ||
* | ||
* Licensed under the BSD 3-Clause License (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://opensource.org/licenses/BSD-3-Clause | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed | ||
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
* CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package main | ||
Check warning on line 18 in examples/configuration/fallback/main.go GitHub Actions / Run Revive Action (1.16.x)
Check warning on line 18 in examples/configuration/fallback/main.go GitHub Actions / Run Revive Action (1.20.x)
Check warning on line 18 in examples/configuration/fallback/main.go GitHub Actions / Run Revive Action (1.18.x)
|
||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/polarismesh/polaris-go" | ||
"github.com/polarismesh/polaris-go/pkg/model" | ||
) | ||
|
||
func main() { | ||
configAPI, err := polaris.NewConfigAPI() | ||
|
||
if err != nil { | ||
fmt.Println("fail to start example.", err) | ||
return | ||
} | ||
|
||
// 获取远程的配置文件 | ||
namespace := "default" | ||
fileGroup := "polaris-config-example" | ||
fileName := "example.yaml" | ||
|
||
configFile, err := configAPI.GetConfigFile(namespace, fileGroup, fileName) | ||
if err != nil { | ||
log.Println("fail to get config.", err) | ||
return | ||
} | ||
|
||
// 打印配置文件内容 | ||
log.Println(configFile.GetContent()) | ||
|
||
// 方式一:添加监听器 | ||
configFile.AddChangeListener(changeListener) | ||
|
||
// 方式二:添加监听器 | ||
changeChan := configFile.AddChangeListenerWithChannel() | ||
|
||
for { | ||
select { | ||
case event := <-changeChan: | ||
log.Printf("received change event by channel. %+v", event) | ||
} | ||
} | ||
} | ||
|
||
func changeListener(event model.ConfigFileChangeEvent) { | ||
log.Printf("received change event. %+v", event) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
global: | ||
serverConnector: | ||
addresses: | ||
- 127.0.0.1:8091 | ||
config: | ||
# 本地缓存配置 | ||
localCache: | ||
#描述: 配置文件持久化到本地开关 | ||
persistEnable: true | ||
#描述: 配置文件持久化目录,SDK在配置文件变更后,把相关的配置持久化到本地磁盘 | ||
persistDir: ./polaris/backup/config | ||
#描述: 配置文件写盘失败的最大重试次数 | ||
persistMaxWriteRetry: 1 | ||
#描述: 配置文件从磁盘读取失败的最大重试次数 | ||
persistMaxReadRetry: 0 | ||
#描述: 缓存读写磁盘的重试间隔 | ||
persistRetryInterval: 500ms | ||
#描述: 远端获取配置文件失败,兜底降级到本地文件缓存 | ||
fallbackToLocalCache: true | ||
configConnector: | ||
addresses: | ||
- 127.0.0.1:8093 | ||
configFilter: | ||
enable: true | ||
chain: | ||
- crypto | ||
plugin: | ||
crypto: | ||
entries: | ||
- name: AES |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.