相关疑难解决方法(0)

如何有效地更新两个struct的值

我有以下代码解析YAML文件,需要匹配一个结构的值external并更新internal结构的type属性.

例如,这是yaml文件(为简单起见翻译为bin)和正确解析的内容

package main

import (
    "fmt"
    "gopkg.in/yaml.v2"
    "log"
)

//internal config model for parsing

type InternalModel struct {
    models []Model2 `yaml:"models"`
}

type Model2 struct {
    Name   string `yaml:"name"`
    Type   string `yaml:"type"`
    Target string `yaml:"target"`
}

var internal_config = []byte(`
 models:
   - name: myapp
     type: app1
     target: ./

   - name: myapp2
     type: app2
     target: ./
`)

type ExternalConfig struct {
    Landscape Zone `yaml:"Landscape"`
}

type Zone struct {
    Zone   string  `yaml:"zone"`
    Models []Model …
Run Code Online (Sandbox Code Playgroud)

recursion struct yaml loops go

7
推荐指数
1
解决办法
427
查看次数

标签 统计

go ×1

loops ×1

recursion ×1

struct ×1

yaml ×1