I'm going to set HCL fields in golang
.
Here the example.
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
", cfg)
}
It's possible to override config
field after called a function hcl.DecodeObject
.
But I'm going to override that field before calling hcl.DecodeObject
.
Is there some way to modify HCL tree?