{"id":13527736,"url":"https://github.com/a8m/envsubst","last_synced_at":"2025-05-13T00:12:55.374Z","repository":{"id":8222472,"uuid":"57315228","full_name":"a8m/envsubst","owner":"a8m","description":"Environment variables substitution for Go","archived":false,"fork":false,"pushed_at":"2025-02-26T19:44:28.000Z","size":755,"stargazers_count":815,"open_issues_count":20,"forks_count":89,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-05-13T00:12:49.189Z","etag":null,"topics":["environment-variables","envsubst","go"],"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/a8m.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":"2016-04-28T16:03:12.000Z","updated_at":"2025-05-08T14:58:32.000Z","dependencies_parsed_at":"2024-10-30T13:00:43.999Z","dependency_job_id":"d74cf9f3-c4c6-466b-b8f2-8efd07cb9631","html_url":"https://github.com/a8m/envsubst","commit_stats":{"total_commits":44,"total_committers":16,"mean_commits":2.75,"dds":0.6136363636363636,"last_synced_commit":"c413ce2c8cc684c32f8ec3da36237f6d5fa46e0a"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a8m%2Fenvsubst","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a8m%2Fenvsubst/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a8m%2Fenvsubst/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a8m%2Fenvsubst/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/a8m","download_url":"https://codeload.github.com/a8m/envsubst/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253843222,"owners_count":21972874,"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":["environment-variables","envsubst","go"],"created_at":"2024-08-01T06:01:59.191Z","updated_at":"2025-05-13T00:12:55.341Z","avatar_url":"https://github.com/a8m.png","language":"Go","funding_links":[],"categories":["开源类库","Go","Open source library","go"],"sub_categories":["配置","Construction"],"readme":"# envsubst\n[![GoDoc][godoc-img]][godoc-url]\n[![License][license-image]][license-url]\n[![Build status][travis-image]][travis-url]\n[![Github All Releases][releases-image]][releases]\n\n\u003e Environment variables substitution for Go. see docs [below](#docs)\n\n#### Installation:\n\n##### From binaries\nLatest stable `envsubst` [prebuilt binaries for 64-bit Linux, or Mac OS X][releases] are available via Github releases.\n\n###### Linux and MacOS\n```console\ncurl -L https://github.com/a8m/envsubst/releases/download/v1.2.0/envsubst-`uname -s`-`uname -m` -o envsubst\nchmod +x envsubst\nsudo mv envsubst /usr/local/bin\n```\n\n###### Windows\nDownload the latest prebuilt binary from [releases page][releases], or if you have curl installed:\n```console\ncurl -L https://github.com/a8m/envsubst/releases/download/v1.2.0/envsubst.exe\n```\n\n##### With go\nYou can install via `go get` (provided you have installed go):\n```console\ngo get github.com/a8m/envsubst/cmd/envsubst\n```\n\n\n#### Using via cli\n```sh\nenvsubst \u003c input.tmpl \u003e output.text\necho 'welcome $HOME ${USER:=a8m}' | envsubst\nenvsubst -help\n```\n\n#### Imposing restrictions\nThere are three command line flags with which you can cause the substitution to stop with an error code, should the restriction associated with the flag not be met. This can be handy if you want to avoid creating e.g. configuration files with unset or empty parameters.\nSetting a `-fail-fast` flag in conjunction with either no-unset or no-empty or both will result in a faster feedback loop, this can be especially useful when running through a large file or byte array input, otherwise a list of errors is returned.\n\nThe flags and their restrictions are: \n\n|__Option__     | __Meaning__    | __Type__ | __Default__  |\n| ------------| -------------- | ------------ | ------------ |\n|`-i`  | input file  | `string \\| stdin` | `stdin`\n|`-o`  | output file | `string \\| stdout` |  `stdout`\n|`-no-digit`  | do not replace variables starting with a digit, e.g. $1 and ${1} | `flag` |  `false` \n|`-no-unset`  | fail if a variable is not set | `flag` |  `false` \n|`-no-empty`  | fail if a variable is set but empty | `flag` | `false`\n|`-fail-fast`  | fails at first occurrence of an error, if `-no-empty` or `-no-unset` flags were **not** specified this is ignored | `flag` | `false`\n\nThese flags can be combined to form tighter restrictions. \n\n#### Using `envsubst` programmatically ?\nYou can take a look on [`_example/main`](https://github.com/a8m/envsubst/blob/master/_example/main.go) or see the example below.\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/a8m/envsubst\"\n)\n\nfunc main() {\n    input := \"welcome $HOME\"\n    str, err := envsubst.String(input)\n    // ...\n    buf, err := envsubst.Bytes([]byte(input))\n    // ...\n    buf, err := envsubst.ReadFile(\"filename\")\n}\n```\n### Docs\n\u003e api docs here: [![GoDoc][godoc-img]][godoc-url]\n\n|__Expression__     | __Meaning__    |\n| ----------------- | -------------- |\n|`${var}`           | Value of var (same as `$var`)\n|`${var-$DEFAULT}`  | If var not set, evaluate expression as $DEFAULT\n|`${var:-$DEFAULT}` | If var not set or is empty, evaluate expression as $DEFAULT\n|`${var=$DEFAULT}`  | If var not set, evaluate expression as $DEFAULT\n|`${var:=$DEFAULT}` | If var not set or is empty, evaluate expression as $DEFAULT\n|`${var+$OTHER}`    | If var set, evaluate expression as $OTHER, otherwise as empty string\n|`${var:+$OTHER}`   | If var set, evaluate expression as $OTHER, otherwise as empty string\n|`$$var`            | Escape expressions. Result will be `$var`. \n\n\u003csub\u003eMost of the rows in this table were taken from [here](http://www.tldp.org/LDP/abs/html/refcards.html#AEN22728)\u003c/sub\u003e\n\n### See also\n\n* `os.ExpandEnv(s string) string` - only supports `$var` and `${var}` notations\n\n#### License\nMIT\n\n[releases]: https://github.com/a8m/envsubst/releases\n[releases-image]: https://img.shields.io/github/downloads/a8m/envsubst/total.svg?style=for-the-badge\n[godoc-url]: https://godoc.org/github.com/a8m/envsubst\n[godoc-img]: https://img.shields.io/badge/godoc-reference-blue.svg?style=for-the-badge\n[license-image]: https://img.shields.io/badge/license-MIT-blue.svg?style=for-the-badge\n[license-url]: LICENSE\n[travis-image]: https://img.shields.io/travis/a8m/envsubst.svg?style=for-the-badge\n[travis-url]: https://travis-ci.org/a8m/envsubst\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fa8m%2Fenvsubst","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fa8m%2Fenvsubst","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fa8m%2Fenvsubst/lists"}