{"id":13651595,"url":"https://github.com/mitchellh/consulstructure","last_synced_at":"2025-04-07T17:09:21.177Z","repository":{"id":57481946,"uuid":"54674124","full_name":"mitchellh/consulstructure","owner":"mitchellh","description":"Decode Consul data into Go (Golang) structures and watch for updates","archived":false,"fork":false,"pushed_at":"2019-03-29T23:18:41.000Z","size":9,"stargazers_count":173,"open_issues_count":0,"forks_count":13,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-31T14:14:34.873Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/mitchellh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-03-24T21:04:59.000Z","updated_at":"2024-10-22T20:17:45.000Z","dependencies_parsed_at":"2022-09-02T06:10:41.815Z","dependency_job_id":null,"html_url":"https://github.com/mitchellh/consulstructure","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitchellh%2Fconsulstructure","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitchellh%2Fconsulstructure/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitchellh%2Fconsulstructure/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitchellh%2Fconsulstructure/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mitchellh","download_url":"https://codeload.github.com/mitchellh/consulstructure/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247694876,"owners_count":20980733,"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-08-02T02:00:50.805Z","updated_at":"2025-04-07T17:09:21.134Z","avatar_url":"https://github.com/mitchellh.png","language":"Go","funding_links":[],"categories":["Go","Projects"],"sub_categories":["Programming Language Clients"],"readme":"# consulstructure\n\nconsulstructure is a Go library for decoding [Consul](https://www.consul.io)\ndata into a Go structure and keeping it in sync with Consul.\n\nThe primary use case for this library is to be able to build native\nConsul-based configuration into your Go applications without needing\nglue such as [consul-template](https://github.com/hashicorp/consul-template).\n\n## Installation\n\nStandard `go get`:\n\n```\n$ go get github.com/mitchellh/consulstructure\n```\n\n## Features\n\nBelow is a high-level feature list:\n\n  * Watch a key prefix in Consul KV to populate a Go structure.\n\n  * Notification on a channel when configuration is updated.\n\n  * Configuration structures support all Go primitive types, maps, and structs.\n    Slices and arrays aren't supported since they don't mean anything in\n    the data model of Consul KV.\n\n  * Nested and embedded structs in configuration structures work.\n\n  * Set quiescence periods to avoid a stampede of configuration updates\n    when many keys are updated in a short period of time.\n\n  * Supports all connection features of Consul: multi-datacenter, encryption,\n    and ACLs.\n\n## Usage \u0026 Example\n\nFor docs see the [Godoc](http://godoc.org/github.com/mitchellh/consulstructure).\n\nAn example is shown below:\n\n```go\nimport (\n    \"fmt\"\n\n    \"github.com/mitchellh/consulstructure\"\n)\n\n// Create a configuration struct that'll be filled by Consul.\ntype Config struct {\n    Addr     string\n    DataPath string `consul:\"data_path\"`\n}\n\n// Create our decoder\nupdateCh := make(chan interface{})\nerrCh := make(chan error)\ndecoder := \u0026consulstructure.Decoder{\n    Target:   \u0026Config{},\n    Prefix:   \"services/myservice\",\n    UpdateCh: updateCh,\n    ErrCh:    errCh,\n}\n\n// Run the decoder and wait for changes\ngo decoder.Run()\nfor {\n    select {\n    case v := \u003c-updateCh:\n        fmt.Printf(\"Updated config: %#v\\n\", v.(*Config))\n    case err := \u003c-errCh:\n        fmt.Printf(\"Error: %s\\n\", err)\n    }\n}\n```\n\n## But Why Not a File?\n\nA file is the most portable and technology agnostic way to get configuration\ninto an application. I'm not advocating this instead of using files for the\ngeneral case.\n\nFor organizations that have chosen Consul as their technology for configuration,\nservices, etc. being able to build services that can be started without\nany further configuration and immediately start running is very attractive.\nYou no longer have a configuration step where you have to setup services\nand file templates and so on with tools like\n[consul-template](https://github.com/hashicorp/consul-template).\n\nYou just install the Go binary, start it, and it is going. To update it,\nyou just update the settings in Consul, and the application automatically\nupdates. No more SIGHUP necessary, no more manual restarts.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmitchellh%2Fconsulstructure","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmitchellh%2Fconsulstructure","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmitchellh%2Fconsulstructure/lists"}