agollo icon indicating copy to clipboard operation
agollo copied to clipboard

[BUG] 无法获取yaml格式的配置

Open leoyox opened this issue 3 years ago • 3 comments

请简单描述bug的场景

如何重现

再现行为的步骤:

  1. apollo创建yaml类型的namespace
  2. 随便写点东西
  3. 使用下面的代码访问并打印
  4. 结果全部为空
x:
  y: true
  myName: false
package main
  2
  3 import (
    "fmt"
    //"strings"
    "github.com/apolloconfig/agollo/v4"
    "github.com/apolloconfig/agollo/v4/env/config"
    "github.com/apolloconfig/agollo/v4/extension"
    "github.com/apolloconfig/agollo/v4/utils/parse/yaml"
    "github.com/apolloconfig/agollo/v4/utils/parse/yml"
    "github.com/apolloconfig/agollo/v4/constant"
)
func init(){

    extension.AddFormatParser(constant.YAML, &yaml.Parser{})
    extension.AddFormatParser(constant.YML, &yml.Parser{})
}
func main() {
    c := &config.AppConfig{
        AppID:          "xxxx",
        Cluster:        "master",
        IP:             "xxxxx",
        NamespaceName:  "application,test.yaml",
    }

    //agollo.SetLogger(&DefaultLogger{})

    client, _ := agollo.StartWithConfig(func() (*config.AppConfig, error) {
        return c, nil
    })
    fmt.Println("初始化Apollo配置成功")
    x:=client.GetConfigCache("test.yaml")
    fmt.Println(x.Get("x.y"))
    fmt.Println(x.Get("x.myName"))
    fmt.Println(x.Get("x.myname"))
    fmt.Println(x)
    y:=client.GetConfig("test.yaml")
    fmt.Println(y.GetContent())
    fmt.Println(y.GetValue("x.myName"))
    fmt.Println(y.GetValue("x.myname"))
    fmt.Println(y.GetValueImmediately("x.myName"))
    fmt.Println(y.GetValueImmediately("x"))
    fmt.Println(y.GetStringValue("x.myName","xx"))
    fmt.Println(y.GetStringValue("x","yy"))
    fmt.Println(y.GetStringValue("x.myname","zz"))
}

leoyox avatar Aug 05 '22 10:08 leoyox

https://github.com/zouyx/agollo_demo/blob/6b681b731d2bc7ae064d9b63803a5b85d4e72f3a/custom/file/check.go

可以直接运行下该部分代码

zouyx avatar Aug 08 '22 11:08 zouyx

https://github.com/zouyx/agollo_demo/blob/6b681b731d2bc7ae064d9b63803a5b85d4e72f3a/custom/file/check.go

可以直接运行下该部分代码

看起来对于yaml只能读取整个文本,不能获取诸如x.y.z

leoyox avatar Aug 08 '22 12:08 leoyox

https://github.com/zouyx/agollo_demo/blob/6b681b731d2bc7ae064d9b63803a5b85d4e72f3a/custom/file/check.go 可以直接运行下该部分代码

看起来对于yaml只能读取整个文本,不能获取诸如x.y.z

apollo 服务端实现上只有 properties 类型的配置支持 key value 读取,其他类型都是文本类型,配置文件的 key 为 content,建议可以自己实现 ChangeList,反解析到对应结构体即可。

why444216978 avatar Aug 25 '22 02:08 why444216978

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Oct 24 '22 02:10 stale[bot]