{"id":13410902,"url":"https://github.com/vrischmann/envconfig","last_synced_at":"2025-05-14T18:06:18.478Z","repository":{"id":30800753,"uuid":"34357835","full_name":"vrischmann/envconfig","owner":"vrischmann","description":"Small library to read your configuration from environment variables","archived":false,"fork":false,"pushed_at":"2025-01-31T10:57:03.000Z","size":96,"stargazers_count":243,"open_issues_count":1,"forks_count":31,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-05-13T19:33:46.079Z","etag":null,"topics":["configuration","go","golang"],"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/vrischmann.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-04-21T23:37:17.000Z","updated_at":"2025-04-24T22:19:39.000Z","dependencies_parsed_at":"2025-02-24T03:10:53.099Z","dependency_job_id":null,"html_url":"https://github.com/vrischmann/envconfig","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vrischmann%2Fenvconfig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vrischmann%2Fenvconfig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vrischmann%2Fenvconfig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vrischmann%2Fenvconfig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vrischmann","download_url":"https://codeload.github.com/vrischmann/envconfig/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254198514,"owners_count":22030965,"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":["configuration","go","golang"],"created_at":"2024-07-30T20:01:10.106Z","updated_at":"2025-05-14T18:06:13.470Z","avatar_url":"https://github.com/vrischmann.png","language":"Go","readme":"envconfig\n=========\n\n![CI](https://github.com/vrischmann/envconfig/workflows/CI/badge.svg)\n[![Go Reference](https://pkg.go.dev/badge/github.com/vrischmann/envconfig.svg)](https://pkg.go.dev/github.com/vrischmann/envconfig)\n\nenvconfig is a library which allows you to parse your configuration from environment variables and fill an arbitrary struct.\n\nSee [the example](https://godoc.org/github.com/vrischmann/envconfig#example-Init) to understand how to use it, it's pretty simple.\n\nSupported types\n---------------\n\n  * Almost all standard types plus `time.Duration` are supported by default.\n  * Slices and arrays\n  * Arbitrary structs\n  * Custom types via the [Unmarshaler](https://godoc.org/github.com/vrischmann/envconfig/#Unmarshaler) interface.\n\nHow does it work\n----------------\n\n*envconfig* takes the hierarchy of your configuration struct and the names of the fields to create a environment variable key.\n\nFor example:\n\n```go\nvar conf struct {\n    Name string\n    Shard struct {\n        Host string\n        Port int\n    }\n}\n```\n\nThis will check for those 3 keys:\n\n  * NAME or name\n  * SHARD\\_HOST, or shard\\_host\n  * SHARD\\_PORT, or shard\\_port\n\nFlexible key naming\n-------------------\n\n*envconfig* supports having underscores in the key names where there is a _word boundary_. Now, that term is not super explicit, so let me show you an example:\n\n```go\nvar conf struct {\n    Cassandra struct {\n        SSLCert string\n        SslKey string\n    }\n}\n```\n\nThis will check all of the following keys:\n\n  * CASSANDRA\\_SSL\\_CERT, CASSANDRA\\_SSLCERT, cassandra\\_ssl\\_cert, cassandra\\_sslcert\n  * CASSANDRA\\_SSL\\_KEY, CASSANDRA\\_SSLKEY, cassandra\\_ssl\\_key, cassandra\\_sslkey\n\nIf that is not good enough, look just below.\n\nCustom environment variable names\n---------------------------------\n\n*envconfig* supports custom environment variable names:\n\n```go\nvar conf struct {\n    Name string `envconfig:\"myName\"`\n}\n```\n\nDefault values\n--------------\n\n*envconfig* supports default values:\n\n```go\nvar conf struct {\n    Name string `envconfig:\"default=Vincent\"`\n}\n```\n\nOptional values\n---------------\n\n*envconfig* supports optional values:\n\n```go\nvar conf struct {\n    Name string `envconfig:\"optional\"`\n}\n```\n\nSkipping fields\n---------------\n\n*envconfig* supports skipping struct fields:\n```go\nvar conf struct {\n    Internal string `envconfig:\"-\"`\n}\n```\n\nCombining multiple options in one tag\n-------------------------------------\n\nYou can of course combine multiple options:\n\n```go\nvar conf struct {\n    Name string `envconfig:\"default=Vincent,myName\"`\n}\n```\n\nSlices or arrays\n----------------\n\nWith slices or arrays, the same naming is applied for the slice. To put multiple elements into the slice or array, you need to separate\nthem with a *,* (will probably be configurable in the future, or at least have a way to escape)\n\nFor example:\n\n```go\nvar conf struct {\n    Ports []int\n}\n```\n\nThis will check for the key __PORTS__:\n\n  * if your variable is *9000* the slice will contain only 9000\n  * if your variable is *9000,100* the slice will contain 9000 and 100\n\nFor slices of structs, it's a little more complicated. The same splitting of slice elements is done with a *comma*, however, each token must follow\na specific format like this: `{\u003cfirst field\u003e,\u003csecond field\u003e,...}`\n\nFor example:\n\n```go\nvar conf struct {\n    Shards []struct {\n        Name string\n        Port int\n    }\n}\n```\n\nThis will check for the key __SHARDS__. Example variable content: `{foobar,9000},{barbaz,20000}`\n\nThis will result in two struct defined in the *Shards* slice.\n\nIf you want to set default value for slice or array, you have to use `;` as separator, instead of `,`:\n\n```go\nvar conf struct {\n    Ports []int `envconfig:\"default=9000;100\"`\n}\n```\n\nSame for slices of structs:\n\n```go\nvar conf struct {\n    Shards []struct {\n        Name string\n        Port int\n    } `envconfig:\"default={foobar;localhost:2929};{barbaz;localhost:2828}\"`\n}\n```\n\nDevelopment state\n-----------------\n\nI consider _envconfig_ to be pretty much done.\n\nIt has been used extensively at [Batch](https://batch.com) for more than 5 years now without much problems,\nwith no need for new features either.\n\nSo, while I will keep maintaining this library (fixing bugs, making it compatible with new versions of Go and so on) for\nthe foreseeable future, I don't plan on adding new features.\n\nBut I'm open to discussion so if you have a need for a particular feature we can discuss it.\n","funding_links":[],"categories":["Configuration","配置","配置管理","配置管理 `配置解析库`","Uncategorized","\u003cspan id=\"组态-configuration\"\u003e组态 Configuration\u003c/span\u003e"],"sub_categories":["Advanced Console UIs","标准CLI","Standard CLI","高級控制台界面","高级控制台界面","标准 CLI","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvrischmann%2Fenvconfig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvrischmann%2Fenvconfig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvrischmann%2Fenvconfig/lists"}