{"id":21726335,"url":"https://github.com/nanvenomous/gofigure","last_synced_at":"2025-04-12T23:09:21.246Z","repository":{"id":164979483,"uuid":"640383804","full_name":"nanvenomous/gofigure","owner":"nanvenomous","description":null,"archived":false,"fork":false,"pushed_at":"2023-05-14T19:52:08.000Z","size":22,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"mainline","last_synced_at":"2025-04-12T23:09:13.531Z","etag":null,"topics":["command-line","configuration","configuration-management","convenient","declarative","explicit","functional-programming","golang","static"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nanvenomous.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":"2023-05-13T22:49:26.000Z","updated_at":"2023-06-12T13:27:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"86b1ab83-89fa-42ed-9f63-33da922ac750","html_url":"https://github.com/nanvenomous/gofigure","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanvenomous%2Fgofigure","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanvenomous%2Fgofigure/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanvenomous%2Fgofigure/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanvenomous%2Fgofigure/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nanvenomous","download_url":"https://codeload.github.com/nanvenomous/gofigure/tar.gz/refs/heads/mainline","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248643004,"owners_count":21138355,"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":["command-line","configuration","configuration-management","convenient","declarative","explicit","functional-programming","golang","static"],"created_at":"2024-11-26T03:24:36.293Z","updated_at":"2025-04-12T23:09:21.228Z","avatar_url":"https://github.com/nanvenomous.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gofigure\n\nGofigure is an opinionated configuration library for go projects\n\n### Install\n```bash\ngo get github.com/nanvenomous/gofigure\n```\n\n### Example\n- run this example directly at [examples/basic](https://github.com/nanvenomous/gofigure/tree/mainline/examples/basic)\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/nanvenomous/gofigure\"\n)\n\n// name your project (to be used for directory naming)\nconst PROJECT_NAME = \"my-gofigure-test-project\"\n\n// Define the structure of your config\ntype myGlobalConfigType struct {\n\tUser struct {\n\t\tName  string `yaml:\"name\"`\n\t\tEmail string `yaml:\"email\"`\n\t} `yaml:\"user\"`\n\tVerbosityLevel uint8 `yaml:\"verbosity_level\"`\n}\n\n// Create a config entity, set default values (if desired)\nvar myGlobalConfig = \u0026myGlobalConfigType{VerbosityLevel: 1}\n\n// Define the explicit interface to your configuration\nfunc SetUsername(unm string) {\n\tgofigure.CheckErr(gofigure.GlobalConfig) // check for file/parsing errors only when accessing config, or replace with your own check, you do you, boo\n\tmyGlobalConfig.User.Name = unm\n}\nfunc Username() string {\n\tgofigure.CheckErr(gofigure.GlobalConfig)\n\treturn myGlobalConfig.User.Name\n}\nfunc VerbosityLevel() uint8 {\n\tgofigure.CheckErr(gofigure.GlobalConfig)\n\treturn myGlobalConfig.VerbosityLevel\n}\n\nfunc main() {\n\tvar err error\n\t// initialize files, set defaults\n\tgofigure.Setup(PROJECT_NAME)\n\tgofigure.Register(gofigure.GlobalConfig, myGlobalConfig) // gofigure supports Global, Local, and Cache configurations\n\n\t// access the config data\n\tfmt.Println(Username())       // \"\"\n\tSetUsername(\"nanvenomous\")    //\n\tfmt.Println(Username())       // \"nanvenomous\"\n\tfmt.Println(VerbosityLevel()) // 1\n\n\t// write the config to disk, so you can get it on next program run\n\tgofigure.WriteAll() // uses go standard lib to coose location by your project name and OS\n\n\t// prints the paths to all your registered config files (in case your user is wondering :)\n\tgofigure.Where() // output depends on your os \u0026 your project name\n\n\t// remove all configuration files (really nice for uninstall scripts)\n\tif err = gofigure.RemoveAll(); err != nil {\n\t\tpanic(err)\n\t}\n}\n```\n\n### Why\n- **Functional api** (so the rest of your project **only needs to consume** the configuration)\n- **Explicit** yet flexible set/get methods\n    - Handle errors... or don't\n    - Return errors or return a zero value\n    - Fail due to config only when config is needed\n    - Essentially it's up to you\n- **Static** config\n    - In-code, automatic defaults that ship with your binary\n    - Config \u0026 file creation on start\n    - No need to guess if values exist (unless you want to)\n- **Convenience methods** for anywhere in application lifecycle\n    - Write everything to disk\n    - List all registered configuration files\n    - Remove all configuration files (nice for uninstall scripts)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnanvenomous%2Fgofigure","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnanvenomous%2Fgofigure","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnanvenomous%2Fgofigure/lists"}