{"id":13410775,"url":"https://github.com/JeremyLoy/config","last_synced_at":"2025-03-14T16:33:00.752Z","repository":{"id":48406787,"uuid":"179086469","full_name":"JeremyLoy/config","owner":"JeremyLoy","description":"12 factor configuration as a typesafe struct in as little as two function calls","archived":false,"fork":false,"pushed_at":"2022-05-30T19:57:34.000Z","size":99,"stargazers_count":336,"open_issues_count":2,"forks_count":15,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-07-31T20:43:59.192Z","etag":null,"topics":["12-factor","cloud","configuration","environment","go","golang","minimal"],"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/JeremyLoy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["JeremyLoy"]}},"created_at":"2019-04-02T13:41:22.000Z","updated_at":"2024-07-03T09:51:48.000Z","dependencies_parsed_at":"2022-08-26T13:23:13.248Z","dependency_job_id":null,"html_url":"https://github.com/JeremyLoy/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/JeremyLoy%2Fconfig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JeremyLoy%2Fconfig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JeremyLoy%2Fconfig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JeremyLoy%2Fconfig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JeremyLoy","download_url":"https://codeload.github.com/JeremyLoy/config/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243610452,"owners_count":20318964,"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":["12-factor","cloud","configuration","environment","go","golang","minimal"],"created_at":"2024-07-30T20:01:09.080Z","updated_at":"2025-03-14T16:33:00.459Z","avatar_url":"https://github.com/JeremyLoy.png","language":"Go","readme":"# Config\n[![PkgGoDev](https://pkg.go.dev/badge/github.com/JeremyLoy/config)](https://pkg.go.dev/github.com/JeremyLoy/config)\n[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge-flat.svg)](https://github.com/avelino/awesome-go)\n[![Build Status](https://github.com/JeremyLoy/config/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/JeremyLoy/config/actions/workflows/ci.yml)\n[![Go Report Card](https://goreportcard.com/badge/github.com/JeremyLoy/config)](https://goreportcard.com/report/github.com/JeremyLoy/config)\n[![Coverage Status](https://coveralls.io/repos/github/JeremyLoy/config/badge.svg?branch=master)](https://coveralls.io/github/JeremyLoy/config?branch=master)\n[![GitHub issues](https://img.shields.io/github/issues/JeremyLoy/config.svg)](https://github.com/JeremyLoy/config/issues)\n[![license](https://img.shields.io/github/license/JeremyLoy/config.svg?maxAge=2592000)](https://github.com/JeremyLoy/config/LICENSE)\n[![Release](https://img.shields.io/github/release/JeremyLoy/config.svg?label=Release)](https://github.com/JeremyLoy/config/releases)\n\nManage your application config as a typesafe struct in as little as two function calls.\n\n```go\ntype MyConfig struct {\n\tDatabaseUrl string `config:\"DATABASE_URL\"`\n\tFeatureFlag bool   `config:\"FEATURE_FLAG\"`\n\tPort        int // tags are optional. PORT is assumed\n\t...\n}\n\nvar c MyConfig\nerr := config.FromEnv().To(\u0026c)\n```\n\n## How It Works\n\nIt's just simple, pure stdlib. \n\n* A field's type determines what [strconv](https://pkg.go.dev/strconv) function is called.\n* All string conversion rules are as defined in the [strconv](https://pkg.go.dev/strconv) package\n* `time.Duration` follows the same parsing rules as [time.ParseDuration](https://pkg.go.dev/time#ParseDuration)\n* `*net.URL` follows the same parsing rules as [url.Parse](https://pkg.go.dev/net/url#URL.Parse)\n  * NOTE: `*net.URL` fields on the struct **must** be a pointer\n* If chaining multiple data sources, data sets are merged. \n  Later values override previous values.\n  ```go\n  config.From(\"dev.config\").FromEnv().To(\u0026c)\n  ```\n    \n* Unset values remain intact or as their native [zero value](https://tour.golang.org/basics/12) \n* Nested structs/subconfigs are delimited with double underscore \n    * e.g. `PARENT__CHILD`\n* Env vars map to struct fields case insensitively\n    * NOTE: Also true when using struct tags.\n* Any errors encountered are aggregated into a single error value\n    * the entirety of the struct is always attempted\n    * failed conversions (i.e. converting \"x\" to an int) and file i/o are the only sources of errors\n        * missing values are not errors\n\n## Why you should use this\n\n* It's the cloud-native way to manage config. See [12 Factor Apps](https://12factor.net/config)\n* Simple:\n    * only 2 lines to configure.\n* Composeable:\n    * Merge local files and environment variables for effortless local development.\n* small:\n    * only stdlib \n    * \u003c 180 LoC\n    \n## Design Philosophy\n\nOpinionated and narrow in scope. This library is only meant to do config binding. \nFeel free to use it on its own, or alongside other libraries.  \n\n* Only structs at the entry point. This keeps the API surface small.  \n\n* Slices are space delimited. This matches how environment variables and commandline args are handled by the `go` cmd.\n\n* No slices of structs. The extra complexity isn't warranted for such a niche usecase.\n\n* No maps. The only feature of maps not handled by structs for this usecase is dynamic keys.\n\n* No pointer members. If you really need one, just take the address of parts of your struct.\n  * One exception is `*url.URL`, which is explicitly a pointer for ease of use, matching the `url` package conventions\n","funding_links":["https://github.com/sponsors/JeremyLoy"],"categories":["Configuration","Go","配置","cloud","配置管理 `配置解析库`","Uncategorized","配置管理"],"sub_categories":["Standard CLI","Advanced Console UIs","标准CLI","标准 CLI"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJeremyLoy%2Fconfig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FJeremyLoy%2Fconfig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJeremyLoy%2Fconfig/lists"}