{"id":19041055,"url":"https://github.com/everythingme/gofigure","last_synced_at":"2025-06-13T01:36:58.757Z","repository":{"id":27849079,"uuid":"31339370","full_name":"EverythingMe/gofigure","owner":"EverythingMe","description":"A simple config file reading library for Go","archived":false,"fork":false,"pushed_at":"2018-09-11T19:59:16.000Z","size":133,"stargazers_count":11,"open_issues_count":0,"forks_count":2,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-23T21:32:54.550Z","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":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/EverythingMe.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":"2015-02-25T22:33:57.000Z","updated_at":"2018-09-11T19:59:24.000Z","dependencies_parsed_at":"2022-09-01T23:20:13.607Z","dependency_job_id":null,"html_url":"https://github.com/EverythingMe/gofigure","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/EverythingMe/gofigure","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EverythingMe%2Fgofigure","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EverythingMe%2Fgofigure/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EverythingMe%2Fgofigure/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EverythingMe%2Fgofigure/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EverythingMe","download_url":"https://codeload.github.com/EverythingMe/gofigure/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EverythingMe%2Fgofigure/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259562526,"owners_count":22877035,"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":[],"created_at":"2024-11-08T22:26:51.164Z","updated_at":"2025-06-13T01:36:58.724Z","avatar_url":"https://github.com/EverythingMe.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GoFigure\n\nGoFigure is a small utility library for reading configuration files. It's usefuly especially if you want to load many files recursively (think `/etc/apache2/mods-enabled/*.conf` on Ubuntu).\n\nIt can support multiple formats, as long as you take a file and unmarshal it into a struct containing your configurations. \n\nRight now the only implemented formats are YAML and JSON files, but feel free to add more :)\n\n## Example usage:\n\n```go \n\nimport (\n\t\"fmt\"\n\t\"github.com/EverythingMe/gofigure\"\n\t\"github.com/EverythingMe/gofigure/yaml\"\n)\n\n// this is our configuration container\nvar conf = \u0026struct {\n\tRedis struct {\n\t\tServer  string\n\t\tMonitor int\n\t\tTimeout int\n\t}\n}{}\n\nfunc main() {\n\t\n\t//if we set some default, the loader will override it\n\tconf.Redis.Server = \"localhost:6377\"\n\n\t// init a loader with a YAML decoder in strict mode\n\tloader := gofigure.NewLoader(yaml.Decoder{}, true)\n\n\t// run recursively on some directory\n\terr := loader.LoadRecursive(conf, \"/etc/myservice/conf.d\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(conf.Redis.Server)\n\t//Output: localhost:6379\n}\n\n```\n\n## Automatic -conf and -confdir flags\n\nGoFigure can automatically add the optional `-conf ` and `-confdir` flags to your program's command line flags, and then\nautomatically read config files specified by them.\n\nTo do that, simply add an import to `\"github.com/EverythingMe/gofigure/autoflag\"`.\n\nYou can then use `autoflag.Load` to load either a single file or all files in the directory specified by these flags.\n\nModifying the above example to do this:\n\n\n```go\n\nimport (\n    // ... other imports ... \n    \n\t\"github.com/EverythingMe/gofigure\"\n    \"github.com/EverythingMe/gofigure/autoflag\"\n)\n\nfunc main() {\n\t\n\t// in this example we also use the default loader which loads yaml files,\n    // but any loader can work here\n    err := autoflag.Load(gofigure.DefaultLoader, \u0026conf)\n    if err != nil {\n\t\tpanic(err)\n\t}\n    \n}\n```\n\n## Reloading configurations on the fly\n\nGoFigure provides a primitive utility for waiting on config reloads. Right now the only implemented method\nis to send a SIGHUP to the process, and have the process using GoFigure use a `ReloadMonitor`, with a `Reloader`\nthat gets called when that signal is sent.\n\nWe do not deal with the actual loading, as each program has its own sensitivites to what parts can be reconfigured in \nruntime and which can't.\n\n### Example:\n\n```go\n\nimport (\n    // ... other imports ... \n    \n\t\"github.com/EverythingMe/gofigure\"\n    \"github.com/EverythingMe/gofigure/autoflag\"\n)\n\n\n// loadConfigs is used both to initially load the configs, and to refresh them\nfunc loadConfigs() {\n\tif err := autoflag.Load(gofigure.DefaultLoader, \u0026conf); err != nil {\n        log.Println(err)\n    }\n}\n\n\nfunc main() {\n\t\n\tloadConfigs()\n    \n    // Create a SignalMonitor that calls a reloader when SIGHUP is sent to our process\n    m := gofigure.NewSignalMonitor()\n    \n    // make the monitor wait for siguhup and call configReload when it needs to\n\tm.Monitor(gofigure.ReloadFunc(loadConfigs))\n    \n}\n\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feverythingme%2Fgofigure","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feverythingme%2Fgofigure","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feverythingme%2Fgofigure/lists"}