{"id":16092275,"url":"https://github.com/alecthomas/hcl","last_synced_at":"2025-04-07T06:12:58.294Z","repository":{"id":36973439,"uuid":"259641559","full_name":"alecthomas/hcl","owner":"alecthomas","description":"Parsing, encoding and decoding of HCL to and from Go types and an AST.","archived":false,"fork":false,"pushed_at":"2025-03-28T00:02:20.000Z","size":119,"stargazers_count":51,"open_issues_count":6,"forks_count":11,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-31T05:06:21.264Z","etag":null,"topics":["golang","hcl"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alecthomas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["alecthomas"]}},"created_at":"2020-04-28T13:15:17.000Z","updated_at":"2025-03-29T18:42:20.000Z","dependencies_parsed_at":"2023-12-02T02:27:15.376Z","dependency_job_id":"ca2bfbab-f409-4cec-b212-b0d577908cfc","html_url":"https://github.com/alecthomas/hcl","commit_stats":{"total_commits":103,"total_committers":8,"mean_commits":12.875,"dds":"0.12621359223300976","last_synced_commit":"9f4ac0b43f9ade2183bae61c97f9f5fa070a7f4e"},"previous_names":[],"tags_count":33,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alecthomas%2Fhcl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alecthomas%2Fhcl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alecthomas%2Fhcl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alecthomas%2Fhcl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alecthomas","download_url":"https://codeload.github.com/alecthomas/hcl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247601449,"owners_count":20964864,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["golang","hcl"],"created_at":"2024-10-09T16:06:32.017Z","updated_at":"2025-04-07T06:12:58.271Z","avatar_url":"https://github.com/alecthomas.png","language":"Go","funding_links":["https://github.com/sponsors/alecthomas"],"categories":[],"sub_categories":[],"readme":"# Parsing, encoding and decoding of HCL to and from Go types\n\n[![](https://godoc.org/github.com/alecthomas/hcl/v2?status.svg)](http://godoc.org/github.com/alecthomas/hcl/v2) [![CircleCI](https://img.shields.io/circleci/project/github/alecthomas/hcl.svg)](https://circleci.com/gh/alecthomas/hcl) [![Go Report Card](https://goreportcard.com/badge/github.com/alecthomas/hcl/v2)](https://goreportcard.com/report/github.com/alecthomas/hcl/v2) [![Slack chat](https://img.shields.io/static/v1?logo=slack\u0026style=flat\u0026label=slack\u0026color=green\u0026message=gophers)](https://gophers.slack.com/messages/CN9DS8YF3)\n\nThis package provides idiomatic Go functions for marshalling and unmarshalling HCL, as well as an AST\n\nIt supports the same tags as the Hashicorp [hcl2](https://github.com/hashicorp/hcl/tree/hcl2)\n`gohcl` package, but is much less complex.\n\nUnlike `gohcl` it also natively supports `time.Duration`, `time.Time`, `encoding.TextUnmarshaler`\nand `json.Unmarshaler`.\n\nIt is HCL1 compatible and does not support any HCL2 specific features.\n\n## Design\n\nHCL -\u003e AST -\u003e Go -\u003e AST -\u003e HCL\n\nMapping can start from any point in this cycle.\n\nMarshalling, unmarshalling, parsing and serialisation are all structurally isomorphic operations. That is, HCL can be\ndeserialised into an AST or Go, or vice versa, and the structure on both ends will be identical.\n\nHCL is always parsed into an AST before unmarshaling and, similarly, Go structures are always mapped to an AST before\nbeing serialised to HCL.\n\nBetween          | And          | Preserves\n-----------------|--------------|-----------------\nHCL              | AST          | Structure, values, order, comments.\nHCL              | Go           | Structure, values, partial comments (via the `help:\"\"` tag).\nAST              | Go           | Structure, values.\n\n## Schema reflection\n\nHCL has no real concept of schemas (that I can find), but there is precedent for something similar in Terraform variable\ndefinition files. This package supports reflecting a rudimentary schema from Go, where the value for each attribute is\none of the scalar types `number`, `string` or `boolean`. Lists and maps are typed by example.\n\nHere's an example schema.\n\n```\n// A string field.\nstr = string\nnum = number\nbool = boolean\nlist = [string]\n\n// A map.\nmap = {\n  string: number,\n}\n\n// A block.\nblock \"name\" {\n  attr = string\n}\n\n// Repeated blocks.\nblock_slice \"label0\" \"label1\" {\n  attr = string\n}\n```\n\nComments are from `help:\"\"` tags. See [schema_test.go](https://github.com/alecthomas/hcl/blob/master/schema_test.go) for\ndetails.\n\n## Struct field tags\n\nThe tag format is as with other similar serialisation packages:\n\n```\nhcl:\"[\u003cname\u003e][,\u003coption\u003e]\"\n```\n\nThe supported options are:\n\nTag                  | Description\n---------------------|--------------------------------------\n`attr` (default)     | Specifies that the value is to be populated from an attribute.\n`block`              | Specifies that the value is to populated from a block.\n`label`              | Specifies that the value is to populated from a block label.\n`optional`           | As with attr, but the field is optional.\n`remain`             | Specifies that the value is to be populated from the remaining body after populating other fields. The field must be of type `[]hcl.Entry`.\n\nAdditionally, a separate `help:\"\"` tag can be specified to populate comment fields in the AST when serialising Go\nstructures.\n\n## Position\n\nAny block with a field named `Pos` of the type `hcl.Position` will have that field populated with positional\ninformation:\n\n```go\nPos Position `hcl:\"-\"`\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falecthomas%2Fhcl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falecthomas%2Fhcl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falecthomas%2Fhcl/lists"}