配置管理

引入依赖

go get github.com/polarismesh/polaris-go@latest

初始化 polaris.yaml

你需要在项目的根路径下创建一个 polaris.yaml 文件用于初始化 polaris-go SDK。polaris.yaml配置详细

SDK实例构建

当初始化好 polaris.yaml 文件之后,你可以直接使用在 package github.com/polarismesh/polaris-go 下的 NewConfigAPI 方法进行构造一个 ConfigAPI SDK 实例

import (
    ...
	"github.com/polarismesh/polaris-go"
)


func main() {
    configAPI, err := polaris.NewConfigAPI()
}

获取配置文件

// namespace: 命名空间
// fileGroup: 配置分组名称
// fileName: 配置文件名称
GetConfigFile(namespace, fileGroup, fileName string) (model.ConfigFile, error)

对配置文件发起监听

func changeListener(event model.ConfigFileChangeEvent) {
}

func main() {
    configFile, err := configAPI.GetConfigFile(namespace, fileGroup, fileName)
    configFile.AddChangeListener(changeListener)
}

查询加密配置

需要更新 polaris-go 的版本至 v1.5.0

// namespace: 命名空间
// fileGroup: 配置分组名称
// fileName: 配置文件名称
GetConfigFile(namespace, fileGroup, fileName string) (model.ConfigFile, error)

调整 polaris.yaml 配置文件

# 配置中心默认配置
config:
  # 配置过滤器
  configFilter:
    enable: true
    chain:
      # 启用配置解密插件
      - crypto
    plugin:
      crypto:
        # 配置解密插件的算法插件类型
        entries:
          - name: AES

如何基于 polaris-go 客户端完成一个配置拉取的程序