【发布时间】:2021-06-02 05:16:45
【问题描述】:
我现在尝试了一切,但无法让这个简单的事情发挥作用。
我收到了以下test_file.hcl:
variable "value" {
test = "ok"
}
我想用下面的代码来解析它:
package hcl
import (
"github.com/hashicorp/hcl/v2/hclsimple"
)
type Config struct {
Variable string `hcl:"test"`
}
func HclToStruct(path string) (*Config, error) {
var config Config
return &config, hclsimple.DecodeFile(path, nil, &config)
但我收到:
test_file.hcl:1,1-1: Missing required argument; The argument "test" is required, but no definition was found., and 1 other diagnostic(s)
我检查了使用同一个库的其他项目,但我找不到我的错误.. 我只是不知道了。有人可以引导我走向正确的方向吗?
【问题讨论】:
-
返回以下诊断信息:
&hcl.Diagnostic{Severity:1, Summary:"Missing required argument", Detail:"The argument \"test\" is required, but no definition was found.", Subject:(*hcl.Range)(0xc0000719c0), Context:(*hcl.Range)(nil), Expression:hcl.Expression(nil), EvalContext:(*hcl.EvalContext)(nil)} &hcl.Diagnostic{Severity:1, Summary:"Unsupported block type", Detail:"Blocks of type \"variable\" are not expected here.", Subject:(*hcl.Range)(0xc0000745d0), Context:(*hcl.Range)(nil), Expression:hcl.Expression(nil), EvalContext:(*hcl.EvalContext)(nil)}