{"id":32907376,"url":"https://github.com/cbonello/gp-config","last_synced_at":"2026-06-16T23:32:04.618Z","repository":{"id":12439023,"uuid":"15096564","full_name":"cbonello/gp-config","owner":"cbonello","description":"Configuration file parser for golang.","archived":false,"fork":false,"pushed_at":"2014-02-04T12:35:17.000Z","size":196,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-06-19T19:42:42.597Z","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/cbonello.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":"2013-12-11T03:02:55.000Z","updated_at":"2024-06-19T19:42:42.598Z","dependencies_parsed_at":"2022-09-26T18:30:40.744Z","dependency_job_id":null,"html_url":"https://github.com/cbonello/gp-config","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/cbonello/gp-config","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cbonello%2Fgp-config","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cbonello%2Fgp-config/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cbonello%2Fgp-config/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cbonello%2Fgp-config/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cbonello","download_url":"https://codeload.github.com/cbonello/gp-config/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cbonello%2Fgp-config/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34428196,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-16T02:00:06.860Z","response_time":126,"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":"2025-11-10T15:32:18.358Z","updated_at":"2026-06-16T23:32:04.609Z","avatar_url":"https://github.com/cbonello.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Configuration File Parser for Go\n\n## Syntax\n\nParser supports a subset of\n[TOML v0.2.0](https://github.com/mojombo/toml/blob/master/versions/toml-v0.2.0.md) syntax.\n\nMain differences are:\n\n* section and option names are case insensitive;\n* sub-sections are not supported;\n* multi-dimensional arrays are not supported;\n* tables are not supported; and\n* array of tables are not supported.\n\nWhy? I just don't need multi-dimensional arrays or tables in my configuration files.\n\nParser implements following grammar ([EBNF](http://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_Form) style):\n\n```\n\tconfig = section | options\n\tsection = '[' IDENTIFIER ']' EOL options\n\toptions = option {option}\n\toption =  IDENTIFIER '=' (value | array) EOL\n\tvalue = BOOL | INT | FLOAT | DATE | STRING\n\tarray = '[' {EOF} value {EOF} {, {EOF} value} {EOF} ']'\n```\n\nParser can load as many configurations as you want, and each load can update existing options.\n\n## Installation\n\n    go get github.com/cbonello/gp-config\n\n## Testing\n\n`gp-config` uses [gocheck](http://labix.org/gocheck) for testing.\n\nTo install gocheck, just run the following command:\n\n\tgo get launchpad.net/gocheck\n\nTo run the test suite, use the following command:\n\n\tgo test github.com/cbonello/gp-config -v\n\nYou can also check test coverage if you're using go 1.2 or later:\n\n\tgo test github.com/cbonello/gp-config -v -coverprofile=test.out\n\tgo tool cover -html=test.out\n\n## Usage\n\n### Loading Configuration Files\n\nConfiguration can either be stored in a string or a file.\n\n```go\nimport (\n\t\"flag\"\n\t\"fmt\"\n\t\"github.com/cbonello/gp-config\"\n\t\"os\"\n)\nconst deflt = `version = [1, 0, 10]\n\t\t\t   [database]\n\t\t\t\t   dbname = \"mydb\"\n\t\t\t\t   user = \"foo\"\n\t\t\t\t   password = \"bar\"`\nvar dev bool = false\nfunc main() {\n\tflag.BoolVar(\u0026dev, \"dev\", false, \"Runs application in debug mode, default is production.\")\n\tflag.Parse()\n\t// Set default options (Production mode).\n\tcfg := config.NewConfiguration()\n\tif err := cfg.LoadString(deflt); err != nil {\n\t\tfmt.Printf(\"error: default config: %d:%d: %s\\n\",\n\t\t\terr.Line, err.Column, err)\n\t\tos.Exit(1)\n\t}\n\tif dev {\n\t\t// Override default options with debug mode settings.\n\t\tif err := cfg.LoadFile(\"debug.cfg\"); err != nil {\n\t\t\tfmt.Printf(\"error: %s: %d:%d: %s\\n\",\n\t\t\t\terr.Filename, err.Line, err.Column, err)\n\t\t\tos.Exit(1)\n\t\t}\n\t}\n\t...\n}\n```\n\nContents of `debug.cfg` may for instance be:\n\n```toml\n[database]\n\tdbname = \"mydb_test\"\n```\n\n### Reading Configuration Files\n\n#### Basic API\n\n```go\n\tif dbname, err := cfg.GetString(\"database.dbname\"); err != nil {\n\t\tfmt.Printf(\"error: configuration: missing database name\\n\")\n\t\tos.Exit(1)\n\t}\n\tuser := cfg.GetStringDefault(\"database.dbname\", \"user\")\n\tpassword := cfg.GetStringDefault(\"database.dbname\", \"foobar\")\n```\n\nSee `examples/demo/` for a complete demo application.\n\nFull API documentation is available at [godoc.org](http://godoc.org/github.com/cbonello/gp-config).\n\n#### Reflection API\n\nFollowing structure may be declared to record options of `[database]` section defined above.\n\n```go\n\ttype database struct {\n\t\tName     string `option:\"dbname\"`\n\t\tUsername string `option:\"user\"`\n\t\tPassword string\n\t}\n```\n\nA structure field annotation may be used if there is no direct match between a field name and an option name.\n\nAnd finally, to decode:\n\n```go\n\tvar db database\n\tif err := cfg.Decode(\"database\", \u0026db); err != nil {\n\t\tfmt.Println(\"error:\", err)\n\t\tos.Exit(1)\n\t}\n```\n\nSee `examples/demo-decode/` for a complete demo application.\n\nFull API documentation is available at [godoc.org](http://godoc.org/github.com/cbonello/gp-config).\n\n## Examples\n\nDemo applications are provided in the `examples/` directory. To launch them:\n\n    go run github.com/cbonello/gp-config/examples/demo/demo.go\n    go run github.com/cbonello/gp-config/examples/demo-decode/demo.go\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcbonello%2Fgp-config","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcbonello%2Fgp-config","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcbonello%2Fgp-config/lists"}