{"id":22993886,"url":"https://github.com/erizocosmico/flagga","last_synced_at":"2025-08-13T22:31:18.220Z","repository":{"id":57491708,"uuid":"136943023","full_name":"erizocosmico/flagga","owner":"erizocosmico","description":"An extensible Go library for handling program configuration using flags.","archived":false,"fork":false,"pushed_at":"2018-09-12T18:53:43.000Z","size":19,"stargazers_count":27,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-02T07:21:12.597Z","etag":null,"topics":["configuration","environment-variables","flags","golang","json"],"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/erizocosmico.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":"2018-06-11T15:08:20.000Z","updated_at":"2023-05-06T21:32:04.000Z","dependencies_parsed_at":"2022-08-30T23:20:54.430Z","dependency_job_id":null,"html_url":"https://github.com/erizocosmico/flagga","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/erizocosmico/flagga","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erizocosmico%2Fflagga","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erizocosmico%2Fflagga/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erizocosmico%2Fflagga/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erizocosmico%2Fflagga/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/erizocosmico","download_url":"https://codeload.github.com/erizocosmico/flagga/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erizocosmico%2Fflagga/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270329018,"owners_count":24565769,"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-13T02:00:09.904Z","response_time":66,"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":["configuration","environment-variables","flags","golang","json"],"created_at":"2024-12-15T05:15:29.635Z","updated_at":"2025-08-13T22:31:17.926Z","avatar_url":"https://github.com/erizocosmico.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# flagga [![GoDoc](https://godoc.org/github.com/erizocosmico/flagga?status.svg)](https://godoc.org/github.com/erizocosmico/flagga) [![Build Status](https://travis-ci.org/erizocosmico/flagga.svg?branch=master)](https://travis-ci.org/erizocosmico/flagga) [![codecov](https://codecov.io/gh/erizocosmico/flagga/branch/master/graph/badge.svg)](https://codecov.io/gh/erizocosmico/flagga) [![Go Report Card](https://goreportcard.com/badge/github.com/erizocosmico/flagga)](https://goreportcard.com/report/github.com/erizocosmico/flagga) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n**flagga** is an extensible Go library for handling program configuration using (but not limited to) command line arguments, environment variables and JSON.\n\nThis idea and API come from [Peter Bourgon's *Go for Industrial Programming*](http://peter.bourgon.org/go-for-industrial-programming/#program-configuration) talk at Gophercon Iceland 2018.\n\nIt should work as a drop-in replacement for the standard library `flag` package. The only difference is the fact that `NewFlagSet` and `Init` accept a second string for the description.\n\n## Goals\n\n- Be able to configure a program with different sources that have different priorities.\n- Be extensible so anyone can extend the API to provide different sources to get their configuration from (yaml, toml, database?, ...).\n- Be a drop-in replacement for the Go standard `flag` package with extra features.\n- Have no third-party dependencies.\n\n## Install\n\n```\ngo get github.com/erizocosmico/flagga\n```\n\nOr use your preferred dependency manager such as dep or vgo.\n\n## Usage\n\n\n```go\nvar fs flagga.FlagSet\n\ndb := fs.String(\"db\", defaultDBURI, \"database connection string\", flagga.Env(\"DBURI\"))\nusers := fs.StringList(\"users\", nil, \"list of allowed users\", flagga.JSON(\"users\"))\n\nerr := fs.Parse(os.Args[1:], flagga.JSONVia(\"config.json\"), flagga.EnvPrefix(\"MYAPP_\"))\nif err != nil {\n    // handle err\n}\n\nfmt.Println(*db) // Outputs: \"user@localhost:1234/foo\"\nfmt.Println(strings.Join(*users, \", \")) // Outputs: \"jane, joe, alice\"\n```\n\nTo get the previous results we can invoke the program in the following ways:\n\n```bash\necho '{\"users\":[\"jane\", \"joe\", \"alice\"]}' \u003e config.json\n./myprogram -db=user@localhost:1234/foo -users=jane -users=joe -users=alice\nMYAPP_DBURI=user@localhost:1234/foo ./myprogram\n```\n\n### Priority of sources\n\nCLI flags **always** have priority over environment variables or JSON keys. If a flag is provided using the command line flags, no other sources will be checked for that variable.\n\nThe rest of the priorities depend of the order in which the sources are passed to the `Parse` method. For example, `fs.Parse(os.Args, flagga.EnvPrefix(\"FOO_\"), flagga.JSONVia(\"cfg\"))` gives more priority to environment variables than to the JSON configuration.\n\n### Available `Extractor`s\n\n- `Env`: from environment variable sources.\n- `JSON`: from JSON sources.\n\nYAML and TOML extractors are available in the [flaggax](https://github.com/erizocosmico/flaggax) repository.\n\n### Available `Source`s\n\n- `EnvPrefix`: provides all environment variables matching the given prefix.\n- `JSONVia`: provides the content of the JSON in the given file.\n\nYAML and TOML sources are available in the [flaggax](https://github.com/erizocosmico/flaggax) repository.\n\n## Custom `Source`s and `Extractor`s\n\nYou can implement your own `Source`s and `Extractor`s in case your configuration is in a different format. Check out the `Source` and `Extractor` interfaces in the package documentation.\n\n### Reference\n\n- [Go `flag` package](http://golang.org/pkg/flag)\n- [*Go for Industrial Programming* by Peter Bourgon](http://peter.bourgon.org/go-for-industrial-programming/#program-configuration)\n\n## License\n\nMIT, see [LICENSE](/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferizocosmico%2Fflagga","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ferizocosmico%2Fflagga","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferizocosmico%2Fflagga/lists"}