{"id":23451220,"url":"https://github.com/peak/go-config","last_synced_at":"2025-04-13T20:15:17.518Z","repository":{"id":46930575,"uuid":"184266793","full_name":"peak/go-config","owner":"peak","description":"Load config files and watch for changes","archived":false,"fork":false,"pushed_at":"2021-09-21T08:14:42.000Z","size":34,"stargazers_count":11,"open_issues_count":0,"forks_count":1,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-13T20:15:12.154Z","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/peak.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":".github/CODEOWNERS","security":null,"support":null}},"created_at":"2019-04-30T13:26:47.000Z","updated_at":"2024-06-02T03:24:41.000Z","dependencies_parsed_at":"2022-09-26T18:41:38.763Z","dependency_job_id":null,"html_url":"https://github.com/peak/go-config","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peak%2Fgo-config","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peak%2Fgo-config/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peak%2Fgo-config/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peak%2Fgo-config/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/peak","download_url":"https://codeload.github.com/peak/go-config/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248774968,"owners_count":21159534,"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-12-24T00:19:49.051Z","updated_at":"2025-04-13T20:15:17.489Z","avatar_url":"https://github.com/peak.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/peak/go-config.svg?branch=master)](https://travis-ci.org/peak/go-config)\n[![Go Report Card](https://goreportcard.com/badge/github.com/peak/go-config)](https://goreportcard.com/report/github.com/peak/go-config)\n\n# go-config\n\nOffers a rich configuration file handler.\n\n- Read configuration files with ease\n- Bind CLI flags\n- Bind environment variables\n- Watch file (or files) and get notified if they change\n\n---\n\nUses the following precedence order:\n\n* `flag`\n* `env`\n* `toml`\n\n\n| flag | env | toml |  result |\n|:----:|:-----:|:-------------:|:---:|\n|  \u0026#9745;   |   \u0026#9745;   |     \u0026#9745;         |  **flag** |\n|  \u0026#9745;   |   \u0026#9745;   |     \u0026#9744;         |  **flag** |\n|  \u0026#9745;   |   \u0026#9744;   |     \u0026#9745;         |  **flag** |\n|  \u0026#9744;   |   \u0026#9745;   |     \u0026#9745;         |  **env** |\n|  \u0026#9745;   |   \u0026#9744;   |     \u0026#9744;         |  **flag** |\n|  \u0026#9744;   |   \u0026#9745;   |     \u0026#9744;         |  **env** |\n|  \u0026#9744;   |   \u0026#9744;   |     \u0026#9745;         |  **toml** |\n\nIf `flag` is set and not given, it will parse `env` or `toml` according to their precedence order (otherwise flag default).\n\n\n## Basic Example\n\nCall the `Load()` method to load a config.\n\n```go\n    type MyConfig struct {\n        Key1    string   `toml:\"key1\"`\n        Key2    string   `toml:\"key2\"`\n        Port    int      `toml:\"-\" flag:\"port\"`\n        Secret  string   `toml:\"-\" flag:\"-\" env:\"secret\"`\n    }\n\n    _ = flag.Int(\"port\", 8080, \"Port to listen on\") // \u003c- notice no variable\n    flag.Parse()\n\n    var cfg MyConfig\n    err := config.Load(\"./config.toml\", \u0026cfg)\n\n    fmt.Printf(\"Loaded config: %#v\\n\", cfg)\n    // Port info is in cfg.Port, parsed from `-port` param\n    // Secret info is in cfg.Secret, parsed from `secret` environment variable\n```\n\n## File Watching\n\nCall `Watch()` method, get a notification channel and listen...\n\n```go\n    ch, err := config.Watch(context.Background(), \"config.toml\")\n\n    for {\n        select {\n        case e := \u003c-ch:\n        \tif e != nil {\n        \t\tfmt.Printf(\"Error occured watching file: %v\", e)\n        \t\tcontinue\n        \t}\n\n            fmt.Println(\"Changed, reloading...\")\n            var cfg MyConfig\n            err := config.Load(\"config.toml\", \u0026cfg)\n            fmt.Printf(\"Loaded: %v %#v\\n\", err, cfg)\n            // Handle cfg...\n        }\n    }\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeak%2Fgo-config","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeak%2Fgo-config","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeak%2Fgo-config/lists"}