Giter VIP home page Giter VIP logo

Comments (2)

apparentlymart avatar apparentlymart commented on June 27, 2024 1

Hi @mattes! Thanks for this question.

HCL is intended as a configuration language rather than as a generic serialization language, and so its API is (as you've seen) a little different than the various "encoding" packages in Go.

In particular, the main HCL API is an abstraction over multiple syntaxes (currently HCL native and JSON) and so the parsing and decoding steps are separated to allow the decoding to be syntax-agnostic while the parsing is (naturally) syntax-specific.

Code generation must also always be syntax-specific. We don't currently have any facility here for generating HCL-as-JSON, but we do have package hclwrite for generating the native syntax. It is a separate package because its API is designed around a physical syntax tree rather than the usual syntax-agnostic model.

Using this API directly gives the most flexibility in how the result is generated (order of body items, spacing between items, etc) but (as @SimonRichardson noticed) there is also a higher-level helper function in gohcl for driving hclwrite, supporting a subset of the struct tags.

This helper is pretty new and I think it wasn't there when this issue was first opened. Since HCL development so far has been prioritizing what Terraform needs (with it being the first big user of the new implementation), hclwrite and this gohcl.EncodeIntoBody function have not yet been put to the test in real use, so they may have bugs, but they are working at least to the extent illustrated in the godoc examples.

I expect we will continue to improve these facilities in future, once the basic HCL functionality is stable. For now though I'm going to close this out since the initial functionality is present. If you try to use these generation functions and find bugs, please feel free to open new issues for them and we will try to get them fixed.

from hcl2.

SimonRichardson avatar SimonRichardson commented on June 27, 2024

@mattes https://github.com/hashicorp/hcl2/blob/master/gohcl/encode_test.go#L45-L47

from hcl2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.