{"id":40873188,"url":"https://github.com/krostar/config","last_synced_at":"2026-01-22T00:42:43.284Z","repository":{"id":57493758,"uuid":"167416824","full_name":"krostar/config","owner":"krostar","description":"Simple and lightweight yet powerful and modulable configuration package","archived":false,"fork":false,"pushed_at":"2020-03-23T10:53:58.000Z","size":109,"stargazers_count":8,"open_issues_count":2,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-06-19T05:45:59.299Z","etag":null,"topics":["config-default","config-loader","config-management"],"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/krostar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-01-24T18:33:38.000Z","updated_at":"2024-06-19T05:45:59.300Z","dependencies_parsed_at":"2022-08-30T04:01:51.780Z","dependency_job_id":null,"html_url":"https://github.com/krostar/config","commit_stats":null,"previous_names":["krostar/configue"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/krostar/config","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krostar%2Fconfig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krostar%2Fconfig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krostar%2Fconfig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krostar%2Fconfig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/krostar","download_url":"https://codeload.github.com/krostar/config/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krostar%2Fconfig/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28648460,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-21T21:29:11.980Z","status":"ssl_error","status_checked_at":"2026-01-21T21:24:31.872Z","response_time":86,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["config-default","config-loader","config-management"],"created_at":"2026-01-22T00:42:42.681Z","updated_at":"2026-01-22T00:42:43.279Z","avatar_url":"https://github.com/krostar.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# config\n\n[![godoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=for-the-badge)](https://godoc.org/github.com/krostar/config)\n[![Licence](https://img.shields.io/github/license/krostar/config.svg?style=for-the-badge)](https://tldrlegal.com/license/mit-license)\n![Latest version](https://img.shields.io/github/tag/krostar/config.svg?style=for-the-badge)\n\n[![Build Status](https://img.shields.io/travis/krostar/config/master.svg?style=for-the-badge)](https://travis-ci.org/krostar/config)\n[![Code quality](https://img.shields.io/codacy/grade/4369c8e78a3e4fd995bac6b963c500b3/master.svg?style=for-the-badge)](https://app.codacy.com/project/krostar/config/dashboard)\n[![Code coverage](https://img.shields.io/codacy/coverage/4369c8e78a3e4fd995bac6b963c500b3.svg?style=for-the-badge)](https://app.codacy.com/project/krostar/config/dashboard)\n\nA simple yet powerful configuration package.\n\n## Motivation\n\nOn any project I've made personnally or for a company, except if the project was really\n(really) small, I always needed at some point to be able to configure a component in the\nproject (the http listening port, the database credentials, a business configuration, ...).\nI've been using **viper** for some times now, but I was not really happy about it for some\nreasons (usage of strings keys to get configuration, globally defined configuration which are\na p.i.t.a. in big project to understand what's used where, and to concurently use and modify in test, ...). I also used **confita** from which this project was inspired.\n\nFrom my point of view a configuration package should:\n\n-   have a **priorization of \"sources\"** (for example file \u0026lt; env \u0026lt; cli args)\n-   be **strongly typed** (it should never use string keys to get a value, or return interface{} left for the call to cast)\n-   be **modulable** (add a new \"source\" to retrieve\n        configuration from vauld or consul for example)\n-   handle **defaults values** (without string keys, and as close as the configuration definition)\n-   have a **clear and easy to use API**\n-   be **light**\n-   encourage and follow the **best practices**\n\nThat's what I tried to do in this configuration package which is made of 4 components:\n\n-   the default setter which handles defaults\n-   the sources (anything that implements one of the two sources interfaces) responsible for\n        the retrieval of the configuration\n-   the \"loader\" which is responsible to set the `default` if any and to call each `sources`\n-   additionally, a validation can be made to make sure configuration is valid\n\n## Usage / examples\n\n```go\n// let's define a structure that hold our http configuration, for example\ntype HTTPConfig struct {\n    Debug          bool\n    ListenAddress  string\n    RequestTimeout time.Duration \n    MACSecret      []byte\n}\n\n// SetDefault sets sane default for http config.\nfunc (c *HTTPConfig) SetDefault() {\n    c.ListenAddress = \":8080\"\n    c.RequestTimeout = 3 * time.Second\n}\n\n// Validate checks whenever the config is properly set.\nfunc (c *HTTPConfig) Validate() error {\n    if c.RequestTimeout \u003c time.Second {\n        return errors.New(\"request timeout is too short (min 1s)\")\n    }\n}\n\nfunc main() {\n    // export PREFIX_DEBUG=\"true\"\n    // export PREFIX_MACSECRET=\"secret\"\n    // echo \"{ \"listen-address\": \":8082\" }\" \u003e ./conf.json\n\n    var cfg HTTPConfig\n\n    if err := config.Load(\u0026cfg, config.WithSources(config.Source{\n        sourcefile.New(\"./conf.json\"),\n        sourceenv.New(\"prefix\"),\n    })); err != nil {\n        panic(err)\n    }\n\n    if err := config.Validate(\u0026cfg); err != nil {\n        panic(err)\n    }\n\n    // cfg.Debug          = \"true\"\n    // cfg.ListenAddress  = \":8082\"\n    // cfg.RequestTimeout = \"3s\"\n    // cfg.MACSecret      = \"secret\"\n}\n```\n\nMore doc and examples in the config's [godoc](https://godoc.org/github.com/krostar/config)\n\n## License\n\nThis project is under the MIT licence, please see the LICENCE file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrostar%2Fconfig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkrostar%2Fconfig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrostar%2Fconfig/lists"}