Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apollo 配置支持解析 yaml json 等 #143

Open
moonheart opened this issue Mar 15, 2021 · 2 comments
Open

apollo 配置支持解析 yaml json 等 #143

moonheart opened this issue Mar 15, 2021 · 2 comments

Comments

@moonheart
Copy link

apollo config.yaml 命名空间配置示例

a:
  b:
    c: 1

apollo 支持 yaml json 等格式的命名空间, 目前的做法是直接作为一个配置, 如 config.yaml 命名空间会被读取成 key 为
config.yaml.content, value 为 yaml 内容的一个配置.

希望可以实现解析, 按照 a.b.c 这样的方式直接读取到配置内容

@tianxiaoliang
Copy link
Member

用户故事是什么,为何会需要同时支持2者,目前是2种分别支持,但是不能同时支持

@moonheart
Copy link
Author

你好, 可能我说的不太清楚, 不是同时支持两者, 是获取到的 apollo 配置没有进行解析, 还是原始的值.

apollo 配置, namespace: test, 类型: yml:

key1:
  key2:
    key3: 1

测试代码:

package main

import (
	"fmt"
	agollo "github.com/Shonminh/apollo-client"
	"github.com/go-chassis/go-archaius"
	"github.com/go-chassis/go-archaius/source/apollo"
)

func main() {
	_ = archaius.Init(archaius.WithRemoteSource(archaius.ApolloSource, &archaius.RemoteInfo{
		URL: "http://config.apollo.net",
		DefaultDimension: map[string]string{
			apollo.AppID:         "appid",
			apollo.NamespaceList: "test.yml",
		},
	}))
	raw, _ := agollo.GetConfigByKey("test.yml.content")
	fmt.Printf("%v:%v\n", "test.yml.content", raw)
	// output:
	// test.yml.content:key1:
	//   key2:
	//     key3: 1

	v, _ := agollo.GetConfigByKey("key1.key2.key3")
	fmt.Printf("%v:%v\n", "key1.key2.key3", v)
	// output:
	// key1.key2.key3:
}

代码中 agollo.GetConfigByKey("key1.key2.key3") 预期输出的值是 apollo 配置中的 1, 结果是没有获取到.

代码中 agollo.GetConfigByKey("test.yml.content") 输出的值是原始的 yml 内容, 说明并没有对 yml 进行解析.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants