duanjia8215 2018-08-21 11:39
浏览 721


Assuming we have two yaml files


someProperty: "someVaue"
anotherProperty: "anotherValue"


someProperty: "overriddenVaue"

Is it possible to unmarshall, merge, and then write those changes to a file without having to define a struct for every property in the yaml file?

The master file has over 500 properties in it that are not at all important to the service at this point of execution, so ideally I'd be able to just unmarshal into a map, do a merge and write out in yaml again but I'm relatively new to go so wanted some opinions.

I've got some code to read the yaml into an interface but i'm unsure on the best approach to then merge the two.

var masterYaml interface{}
yamlBytes, _ := ioutil.ReadFile("master.yaml")
yaml.Unmarshal(yamlBytes, &masterYaml)

var overrideYaml interface{}
yamlBytes, _ = ioutil.ReadFile("override.yaml")
yaml.Unmarshal(yamlBytes, &overrideYaml)

I've looked into libraries like mergo but i'm not sure if that's the right approach.

I'm hoping that after the master I would be able to write out to file with properties

someProperty: "overriddenVaue"
anotherProperty: "anotherValue"
  • 写回答



      相关推荐 更多相似问题


      • ¥50 有没有大佬看一下关于思科的这道题怎么做
      • ¥30 求十字路口交通灯S7-200plc,今天早上八点前。
      • ¥20 如何用智能手表oppowatch3实现个人热点功能
      • ¥15 运营商打开wanpush会有怎么样的危害
      • ¥15 Java编程题,定义一个时钟
      • ¥15 Python面向对象编程——生成多项式的一阶导数
      • ¥15 在编写C++程序遇到了问题
      • ¥15 java程序查找字符串中所有的回文并输出
      • ¥15 怎么让只支持对.exe 和.dll文件进行加壳的加壳器,同时让它也支持php文件加壳呢
      • ¥15 这两个数学公式什么意思?