{"id":18273973,"url":"https://github.com/distributedio/configo","last_synced_at":"2025-10-05T18:16:25.697Z","repository":{"id":57483207,"uuid":"61346700","full_name":"distributedio/configo","owner":"distributedio","description":"Configo is a go library to parse toml configuration using struct tags","archived":false,"fork":false,"pushed_at":"2023-02-25T00:37:24.000Z","size":58,"stargazers_count":32,"open_issues_count":5,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-02T21:15:39.830Z","etag":null,"topics":["configo","toml"],"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/distributedio.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}},"created_at":"2016-06-17T05:00:21.000Z","updated_at":"2022-12-26T22:50:44.000Z","dependencies_parsed_at":"2023-07-13T10:45:41.325Z","dependency_job_id":null,"html_url":"https://github.com/distributedio/configo","commit_stats":{"total_commits":87,"total_committers":5,"mean_commits":17.4,"dds":0.09195402298850575,"last_synced_commit":"efd79b027816dc80eaa6a5806594e17206623584"},"previous_names":["shafreeck/configo"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/distributedio%2Fconfigo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/distributedio%2Fconfigo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/distributedio%2Fconfigo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/distributedio%2Fconfigo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/distributedio","download_url":"https://codeload.github.com/distributedio/configo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246981795,"owners_count":20863961,"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":["configo","toml"],"created_at":"2024-11-05T12:08:13.647Z","updated_at":"2025-10-05T18:16:20.657Z","avatar_url":"https://github.com/distributedio.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Configo\nConfigo is a go library to parse toml configuration using struct tags\n\n## Features\n* Configuring parser behaviour using struct tags\n* Setting default value or as required\n* Validating value using regex, range expression or named validator\n* Generating toml template with human friendly information based on go struct and tags\n* Building conf file generation tools using configo-build\n\n## QuickStart\n\n* Install `configo-build` tool for config generation\n\u003e go get github.com/distributedio/configo/bin/configo-build\n\n* Define a struct in package conf\n```go\npackage conf\n\ntype Config struct {\n        Listen  string `cfg:\"listen; :8804; netaddr; The address the server to listen\"`\n        MaxConn int    `cfg:\"max-connection; 10000; numeric; Max number of concurrent connections\"`\n        Redis   struct {\n                Cluster []string `cfg:\"cluster; required; dialstring; The addresses of redis cluster\"`\n        }\n}\n```\n\n* Use `configo-build` tool generate config builder, if everything goes well, you'll get a binary called `conf.Config.cfg`\n\n\u003e configo-build ./conf.Config\n\nor use the absolute path\n\n\u003e configo-build github.com/distributedio/configo/example/conf.Config\n\n* execute builer to generate a toml\n\u003e conf.config.cfg \u003e conf.toml\n\nor patch you toml file if it is already existed\n\n\u003e conf.config.cfg -patch conf.toml\n\n* Use your config in your code\n\n```go\nimport \"github.com/distributedio/configo\"\n\nvar conf conf.Config\n\nif err := configo.Parse(\"{PATH_TO_YOUR_TOML}\", \u0026conf) ;err != nil {\n// handle the error\n}\n\n```\n\n## Toml\n[shafreeck/toml](https://github.com/shafreeck/toml) is a modification version of [naoina/toml](https://github.com/naoina/toml),\nadding the abililty to parse complex struct tags and with bugs fixed.\n\n## Validation\nconfigo has a builtin validator with regex and range support\n\n___Supported named validator___\n\n* netaddr\n* url\n* nonempty\n* dialstring\n* boolean\n* numeric\n* printableascii\n* path\n\nand you can also use compare operator and regExp in tags\n\n```go\n\u003e 1 //greater than 1\n\u003e=1 //greater than or equal to 1\n\u003e1 \u003c10 //greater than 1 and less than 10, space indicates the \"and\" of rules\n\n(1, ) //range expression, same as \u003e1\n(1, 10) // \u003e1 \u003c10\n(1,10]  // \u003e1 \u003c=10\n\n/[0-9]/ //regex matching\n\n/[0-9]+/ (1, 10) // the value should satisfy both the regex and range expression\n\nnetaddr //named validator, used to validate a network address\nnumeric  \u003e10 ( ,100)// mix different expressions, 'and' is used to combine all expressions\n```\n\nSee the [Suppoted Vaildator](https://github.com/distributedio/configo/blob/master/rule/named.go#L12) for all valid \"named validators\"\n\n## Struct tags\n\n`tags` has a key 'cfg' and its value consists of four parts: \"name; default value or required; rule; descripion\".\nAll four parts are splited by \";\".\n\nFor example:\n```go\nListen `cfg:\"listen; :8804; netaddr; The listen address of server\"`\n```\n\nIt looks like this when being marshaled to toml\n```toml\n#type:        string\n#rules:       netaddr\n#description: The listen address of server\n#default:     :8804\n#listen=\":8804\"\n```\n\nYou can see that we have rich information about the option. And the option is commented out too because it has a default value.\n\n## configo-build\nConfigo comes with a util tool called configo-build to build a configration file generator for you.\n\nYou can use the generator to generate your toml file or update it when you changed your source code(the configuration struct).\n\n```sh\nconfigo-build ./conf.Config\n#build a conf generator, the format of arg is \"package.struct\" package can be\n#absolute or relative(golang takes it as an absolute package if it is without\n#the prefix \"./\" or \"../\").\n\n#the built program has a name with format:\u003cpackage\u003e.\u003cstruct\u003e.cfg, for example\n#\"conf.config.cfg\"\n```\n\nGenerating your configuration file with the built generator\n```sh\nconf.config.cfg \u003e conf.toml #generating\nconf.config.cfg -patch conf.toml #updating if conf.toml has already existed\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdistributedio%2Fconfigo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdistributedio%2Fconfigo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdistributedio%2Fconfigo/lists"}