{"id":17355151,"url":"https://github.com/zephinzer/go-config","last_synced_at":"2025-08-04T03:35:17.593Z","repository":{"id":57693815,"uuid":"429644228","full_name":"zephinzer/go-config","owner":"zephinzer","description":null,"archived":false,"fork":false,"pushed_at":"2021-11-19T02:31:48.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-27T14:17:03.661Z","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/zephinzer.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}},"created_at":"2021-11-19T02:24:49.000Z","updated_at":"2021-11-19T02:31:51.000Z","dependencies_parsed_at":"2022-09-26T21:01:12.313Z","dependency_job_id":null,"html_url":"https://github.com/zephinzer/go-config","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/zephinzer/go-config","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zephinzer%2Fgo-config","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zephinzer%2Fgo-config/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zephinzer%2Fgo-config/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zephinzer%2Fgo-config/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zephinzer","download_url":"https://codeload.github.com/zephinzer/go-config/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zephinzer%2Fgo-config/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268644684,"owners_count":24283358,"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","status":"online","status_checked_at":"2025-08-04T02:00:09.867Z","response_time":79,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2024-10-15T17:42:29.019Z","updated_at":"2025-08-04T03:35:17.571Z","avatar_url":"https://github.com/zephinzer.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-config\n\n![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/zephinzer/go-config)\n[![pipeline status](https://gitlab.com/zephinzer/go-config/badges/master/pipeline.svg)](https://gitlab.com/zephinzer/go-config/-/commits/master)\n[![coverage report](https://gitlab.com/zephinzer/go-config/badges/master/coverage.svg)](https://gitlab.com/zephinzer/go-config/-/commits/master)\n\n\nAn intuitive configuration loader for use in Golang applications.\n\n- [go-config](#go-config)\n- [Usage](#usage)\n  - [Importing](#importing)\n  - [Example](#example)\n    - [A fully featured struct](#a-fully-featured-struct)\n    - [Load()](#load)\n- [Documentation](#documentation)\n  - [Variable name parsing](#variable-name-parsing)\n  - [Supported types of variables](#supported-types-of-variables)\n  - [Supported struct tags](#supported-struct-tags)\n- [Contributing](#contributing)\n  - [Changelog](#changelog)\n  - [Potential roadmap](#potential-roadmap)\n- [License](#license)\n\n# Usage\n\n## Importing\n\n```go\nimport \"github.com/zephinzer/go-config\"\n```\n\n## Example\n\n### A fully featured struct\n\nThe following is a fully featured configuration `struct` which can be passed to the `.Load*()` methods for retrieving values from the environment.\n\n```go\ntype MyConfiguration struct {\n\tOptionalBool                               *bool\n\tOptionalBoolWithCustomEnv                  *bool `env:\"CUSTOM_BOOL\"`\n\tOptionalInt                                *int\n\tOptionalString                             *string\n\tOptionalStringSlice                        *[]string\n\tRequiredBool                               bool\n\tRequiredBoolWithDefault                    bool `default:\"true\"`\n\tRequiredInt                                int\n\tRequiredIntWithDefault                     int `default:\"-12345\"`\n\tRequiredString                             string\n\tRequiredStringWithDefault                  string `default:\"required-string\"`\n\tRequiredStringSlice                        []string\n\tRequiredStringSliceWithDefault             []string `default:\"required,string,slice\"`\n\tRequiredStringSliceWithDefaultAndDelimiter []string `default:\"required|string|slice\" delimiter:\"|\"`\n}\n```\n\n### Load()\n\nSee [./example/load/main.go](./example/load/main.go) for a fully-featured example.\n\nTo get an idea of how the different struct tags work, clone this repository and try the example by running:\n\n```sh\nCUSTOM_BOOL=true \\\n  REQUIRED_BOOL=true \\\n  REQUIRED_INT=-54321 \\\n  REQUIRED_STRING=\"hello world\" \\\n  REQUIRED_STRING_SLICE=\"hello,world\" \\\n  go run ./example/load;\n```\n\nYou should get the following pretty-printed JSON output:\n\n```json\n{\n  \"OptionalBool\": null,\n  \"OptionalBoolWithCustomEnv\": true,\n  \"OptionalInt\": null,\n  \"OptionalString\": null,\n  \"OptionalStringSlice\": null,\n  \"RequiredBool\": true,\n  \"RequiredBoolWithDefault\": true,\n  \"RequiredInt\": -54321,\n  \"RequiredIntWithDefault\": -12345,\n  \"RequiredString\": \"hello world\",\n  \"RequiredStringWithDefault\": \"required-string\",\n  \"RequiredStringSlice\": [\n    \"hello\",\n    \"world\"\n  ],\n  \"RequiredStringSliceWithDefault\": [\n    \"required\",\n    \"string\",\n    \"slice\"\n  ],\n  \"RequiredStringSliceWithDefaultAndDelimiter\": [\n    \"required\",\n    \"string\",\n    \"slice\"\n  ]\n}\n```\n\n# Documentation\n\n## Variable name parsing\n\nThis library converts variable names in your provided configuration `struct` into `UPPER_SNAKE_CASE` and checks the environment for these keys. The library [`go-strcase`](https://github.com/zephinzer/go-strcase) is used to parse the variable names into environment variables. Here are some examples of the transformation:\n\n| Variable name | Derived environment value key |\n| --- | --- |\n| someString | `SOME_STRING` |\n| SomeNumber | `SOME_NUMBER` |\n| endpointURL | `ENDPOINT_URL` |\n| IsURLSetCorrectly | `IS_URL_SET_CORRECTLY` |\n\n## Supported types of variables\n\n| Type | Golang type |\n| --- | --- |\n| Boolean | `bool` |\n| Optional boolean | `*bool` |\n| Number | `int` |\n| Optional number | `*int` |\n| String | `string` |\n| Optional string | `*string` |\n| String Slice | `[]string` |\n| Optional string slice | `*[]string` |\n\n## Supported struct tags\n\nStruct tags are used to provide metadata for the `.Load*()` methods to process. The following are the available struct tags:\n\n| Struct tag | Example | Description |\n| --- | --- | --- |\n| `default` | `default:\"153\"` | Defines a default value for the variable. This has to be specified as a string; if the type of the property is not a string, the library parses the provided string value into the required type. |\n| `delimiter` | `delimiter:\"custom_bool\"` | Applies only to slice types and defines the delimiter which should be used. This defaults to the comma character - `,` |\n| `env` | `env:\"custom_bool\"` | Defines the environment variable key to use instead of the default one derived from the property name |\n\n# Contributing\n\nThe working repository is at Gitlab at [https://gitlab.com/zephinzer/go-config](https://gitlab.com/zephinzer/go-config), if you are seeing this on Github, it's just for SEO since y'know all the cool new kids are on Github 😂\n\n## Changelog\n\nA rough changelog when the contributors can remember to add it is here:\n\n| Version  | Description                                                                                                                                 |\n| -------- | ------------------------------------------------------------------------------------------------------------------------------------------- |                                         |\n| `v1.0.0` | Initial release |\n\n## Potential roadmap\n\nIf you'd like to contribute, here are some features I have a distant-future need to implement but haven't gotten round to doing:\n\n- [ ] Implement a `.Load*()` method that consumes variable values from derived flag names (probably convert to `--lower-kebab-case` and provide a struct tag to define the shorthand flag notation)\n- [ ] Implement a `.Load*()` method that consumes variable values from a file instead of environment variables\n- [ ] Integration with `spf13/cobra` via `PreRun` or `PersistentPreRun` to automatically run and get values\n- [ ] Integration with `spf13/cobra` AND `spf13/viper` via `PersistentFlags` to automatically run and get values from flags\n\n# License\n\nUse this anywhere you need to. Licensed under [the MIT license](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzephinzer%2Fgo-config","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzephinzer%2Fgo-config","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzephinzer%2Fgo-config/lists"}