{"id":16092297,"url":"https://github.com/alecthomas/kong-hcl","last_synced_at":"2025-03-18T06:30:59.642Z","repository":{"id":45983485,"uuid":"148141276","full_name":"alecthomas/kong-hcl","owner":"alecthomas","description":null,"archived":false,"fork":false,"pushed_at":"2024-02-01T17:48:04.000Z","size":51,"stargazers_count":8,"open_issues_count":3,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-16T17:45:13.170Z","etag":null,"topics":[],"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":"2018-09-10T10:52:47.000Z","updated_at":"2024-10-06T13:45:13.000Z","dependencies_parsed_at":"2024-06-18T21:34:12.879Z","dependency_job_id":"46662670-58ab-4c29-9243-f54b1940908f","html_url":"https://github.com/alecthomas/kong-hcl","commit_stats":{"total_commits":38,"total_committers":4,"mean_commits":9.5,"dds":0.07894736842105265,"last_synced_commit":"98e50d023e3b02b1908a8773a81732c72e2e6464"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alecthomas%2Fkong-hcl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alecthomas%2Fkong-hcl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alecthomas%2Fkong-hcl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alecthomas%2Fkong-hcl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alecthomas","download_url":"https://codeload.github.com/alecthomas/kong-hcl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244169367,"owners_count":20409705,"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":[],"created_at":"2024-10-09T16:06:51.363Z","updated_at":"2025-03-18T06:30:59.080Z","avatar_url":"https://github.com/alecthomas.png","language":"Go","funding_links":["https://github.com/sponsors/alecthomas"],"categories":[],"sub_categories":[],"readme":"# A Kong configuration loader for HCL [![](https://godoc.org/github.com/alecthomas/kong-hcl?status.svg)](http://godoc.org/github.com/alecthomas/kong-hcl) [![CircleCI](https://img.shields.io/circleci/project/github/alecthomas/kong-hcl.svg)](https://circleci.com/gh/alecthomas/kong-hcl)\n\nThis is version 1.x of kong-hcl. [Version 2](https://github.com/alecthomas/kong-hcl/tree/master/v2)\nof this package uses the HCL2 library but is otherwise largely a drop-in replacement\n(see the README for details).\n\nUse it like so:\n\n```go\nvar cli struct {\n    Config kong.ConfigFlag `help:\"Load configuration.\"`\n}\nparser, err := kong.New(\u0026cli, kong.Configuration(konghcl.Loader, \"/etc/myapp/config.hcl\", \"~/.myapp.hcl))\n```\n\n## Mapping HCL fragments to a struct\n\nMore complex structures can be loaded directly into flag values by implementing the\n`kong.MapperValue` interface, and calling `konghcl.DecodeValue`. \n\nThe value can either be a HCL(/JSON) fragment, or a path to a HCL file that will be loaded. Both\ncan be specified on the command-line or config file.\n\neg.\n\n```go\ntype NestedConfig struct {\n\tSize int\n\tName string\n}\n\ntype ComplexConfig struct {\n\tKey bool\n\tNested map[string]NestedConfig\n}\n\nfunc (c *ComplexConfig) Decode(ctx *kong.DecodeContext) error {\n\treturn konghcl.DecodeValue(ctx, c)\n}\n\n// ...\n\ntype Config struct {\n\tComplex ComplexConfig\n}\n```\n\nThen the following `.hcl` config fragment will be decoded into `Complex`:\n\n```hcl\ncomplex {\n  key = true\n  nested first {\n    size = 10\n    name = \"first name\"\n  }\n  nested second {\n    size = 12\n    name = \"second name\"\n  }\n}\n```\n\n## Configuration layout\n\nConfiguration keys are mapped directly to flags.\n\nAdditionally, HCL block keys will be used as a hyphen-separated prefix when looking up flags.\n\n## Example\n\nThe following Kong CLI:\n\n```go\ntype CLI struct {\n  Debug bool\n  DB struct {\n    DSN string\n    Trace bool\n  } `embed:\"\" prefix:\"db-\"`\n}\n```\n\nMaps to the following flags:\n\n```\n--debug\n--db-dsn=\u003cstring\u003e\n--db-trace\n```\n\nAnd can be configured via the following HCL configuration file...\n\n```hcl\ndebug = true\n\ndb {\n    dsn = \"root@/database\"\n    trace = true\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falecthomas%2Fkong-hcl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falecthomas%2Fkong-hcl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falecthomas%2Fkong-hcl/lists"}