在golang中设置HCL字段

时间:2018-04-23 09:21:20

标签: go hcl

我要在golang中设置HCL字段。 这是一个例子。

package main

import (
    "log"
    "os"

    "github.com/hashicorp/hcl"
)

const (
    EXAMPLE_HCL = `config = "/etc/test.conf"`
)

type HCLConfig struct {
    ConfigFile          string     `hcl:"config"`
}

func main() {
    cfg := &HCLConfig{}

    hclTree, err := hcl.Parse(EXAMPLE_HCL)
    if err != nil {
        os.Exit(1)
    }

    // how to modify tree to override config field

    if err := hcl.DecodeObject(&cfg, hclTree); err != nil {
        os.Exit(1)
    }

    log.Printf("%+v\n", cfg)
}

在调用函数config后,可以覆盖hcl.DecodeObject字段。

但是在调用hcl.DecodeObject之前我会覆盖该字段。

有没有办法修改HCL树?

0 个答案:

没有答案
相关问题