Open VoyTechnology opened 5 years ago
Hi @VoyTechnology! Thanks for reporting this.
gohcl
currently intentionally ignores any field that doesn't have a hcl:
struct tag on it, so this behavior is consistent with that decision, but I agree that it could be useful to make an exception in this case to treat an embedded struct as if its fields were just inline in the embedder.
I expect we will not have time to work on this in the near future, but if you have the time and motivation to work on it I'd be happy to review a pull request.
Issue description
When using composition of a Go structures, the HCL cannot be parsed using
gohcl
.Steps to reproduce the issue
import ( "encoding/json" "fmt"
)
type File struct { A A
hcl:"a,block" json:"a"
}type A struct { B }
type B struct { Foo string
json:"foo" hcl:"foo"
}var hclBody = []byte(
a { foo = "bar" }
)var jsonBody = []byte(
{ "a":{ "foo":"bar" } }
)func main() { // JSON var j File if err := json.Unmarshal(jsonBody, &j); err != nil { fmt.Println("json.Unmarshal:", err) return } js, _ := json.MarshalIndent(j, "", "\t") fmt.Println(string(js))
}
What's the actual result
Error is being thrown
Additional details
go version go1.12.5 darwin/amd64
go get -u
just before running the command, hcl2 at versionv0.0.0-20190515223218-4b22149b7cef