{"id":22609602,"url":"https://github.com/imoore76/configurature","last_synced_at":"2025-04-10T22:38:17.124Z","repository":{"id":266921421,"uuid":"899769954","full_name":"imoore76/configurature","owner":"imoore76","description":"Simple, flexible, and powerful application configuration for Go.","archived":false,"fork":false,"pushed_at":"2025-03-11T00:25:07.000Z","size":607,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-24T19:22:22.375Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/imoore76.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":"supported_types_test.go","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-07T01:23:51.000Z","updated_at":"2025-03-24T14:38:26.000Z","dependencies_parsed_at":"2024-12-07T02:24:02.907Z","dependency_job_id":"6b6c4016-0e57-4913-add1-e211272c60bb","html_url":"https://github.com/imoore76/configurature","commit_stats":null,"previous_names":["imoore76/configurature"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imoore76%2Fconfigurature","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imoore76%2Fconfigurature/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imoore76%2Fconfigurature/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imoore76%2Fconfigurature/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/imoore76","download_url":"https://codeload.github.com/imoore76/configurature/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248311924,"owners_count":21082633,"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-12-08T15:13:51.208Z","updated_at":"2025-04-10T22:38:17.113Z","avatar_url":"https://github.com/imoore76.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Configurature\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"logo.png\" height=\"384\" width=\"384\" alt=\"configurature logo\" /\u003e\n\u003c/p\u003e\n\nConfigurature is a Go library that provides declarative app configuration using structs.\nIt is designed with sensible default behavior while allowing for fine-grained\nconfiguration if desired. Born from the desire to simply specify a config struct without\nhaving to worry about specifying *every*, *single* field's environment variable and command line flag.\n\nConfiguration values can be specified (in value precedence order) on the command line,\nusing environment variables, and/or in a config file (yaml or json).\n\nConfiguration structs can be composed in a way that your application's entry points do not\nneed to be aware of the structure of other packages' configurations in order to initialize them.\n\nSee the complete documentation at [http://configurature-docs.readthedocs.io](http://configurature-docs.readthedocs.io).\n\n## Basic Usage\n\nBasic usage consists of defining your configuration structs and running `configurature.Configure()`.\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"net\"\n\t\"time\"\n\n\tco \"github.com/imoore76/configurature\"\n)\n\ntype Config struct {\n\tWaitTimeout time.Duration `default:\"30s\"`\n\tListenIP    net.IP        `default:\"127.0.0.1\"`\n\tListenPort  int           `default:\"8080\"`\n\tServerName  string\n}\n\nfunc main() {\n\n\tconf := co.Configure[Config](\u0026co.Options{\n\t\tEnvPrefix: \"MYAPP_\",\n\t})\n\n\tfmt.Printf(\"Wait Timeout: %s\\n\", conf.WaitTimeout)\n\tfmt.Printf(\"IP: %s\\n\", conf.ListenIP)\n\tfmt.Printf(\"Port: %d\\n\", conf.ListenPort)\n\tfmt.Printf(\"Server name: %s\\n\", conf.ServerName)\n\n}\n```\nYou get CLI args and environment variable support without having to tediously\nspecify them.\n\n```shell\nuser@host $ MYAPP_LISTEN_IP=0.0.0.0 myapp --listen_port 6000\nWait Timeout: 30s\nIP: 0.0.0.0\nPort: 6000\nServer name: \n```\n\nRunning this app with `--help` displays the app usage:\n\n```shell\nCommand usage:\n  -h, --help                    show help and exit\n      --listen_ip ip            listen ip (default 127.0.0.1)\n      --listen_port int         listen port (default 8080)\n      --server_name string      server name\n      --wait_timeout duration   wait timeout (default 30s)\n```\n\n\n## Complex Usage\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"net\"\n\n\t// Package in \"myapp\" with a Config struct defined\n\t\"github.com/me/myapp/theme\"\n\n\tco \"github.com/imoore76/configurature\"\n)\n\n// Database config struct.\ntype DBConfig struct {\n\tHost     string `required:\"\"`              // this field is required\n\tPort     int    `default:\"5432\" short:\"p\"` // specify \"short\" flag\n\tUser     string `default:\"postgres\"`\n\tPassword string `default:\"postgres\"`\n}\n\n// Network server config struct. Could also reside in a different package.\ntype ServerConfig struct {\n\tServerName  string `name:\"hostname\"` // rename this field in the config\n\tReadTimeout int    // no struct tags are required\n\tListenIP    net.IP `help:\"IP address on which to listen\" default:\"127.0.0.1\"`\n\tListenPort  uint   `default:\"8080\"`\n}\n\ntype Config struct {\n\tServerConfig                  // Embedded struct\n\tDB              DBConfig      // Sub-config in `DB` struct\n\tTheme           theme.Config  // Sub-config from \"theme\" package\n\tCalculatedField string        `ignore:\"\"`                                   // ignore this field\n\tLogLevel        string        `default:\"info\" enum:\"debug,info,warn,error\"` // enum field\n\tConf            co.ConfigFile `help:\"Configuration file\"`                   // config file\n}\n\nfunc main() {\n\n\tconf := co.Configure[Config](\u0026co.Options{\n\t\tEnvPrefix: \"MYAPP_\",\n\t})\n\n\tfmt.Printf(\"DB Host: %s\\n\", conf.DB.Host)\n\tfmt.Printf(\"Log level: %s\\n\", conf.LogLevel)\n\tfmt.Printf(\"IP: %s\\n\", conf.ListenIP)\n\tfmt.Printf(\"Port: %d\\n\", conf.ListenPort)\n\n  /*\n  E.g.\n\n  setLogLevel(conf.LogLevel)\n  \n  initDB(conf.DB)\n  \n  theme.SetDisplay(conf.Theme)\n  \n  runServer(conf.ServerConfig)\n  */\n}\n```\n\nRunning this app with `--help` displays the app usage:\n\n```\nCommand usage:\n      --conf configFile      Configuration file\n      --db_host string       db host\n      --db_password string   db password (default \"postgres\")\n  -p, --db_port int          db port (default 5432)\n      --db_user string       db user (default \"postgres\")\n  -h, --help                 show help and exit\n      --hostname string      hostname\n      --listen_ip ip         IP address on which to listen (default 127.0.0.1)\n      --listen_port uint     listen port (default 8080)\n      --log_level string     log level (debug|info|warn|error) (default \"info\")\n      --read_timeout int     read timeout\n      --theme_fg rgb         Foreground color (default #FFFFFF)\n      --theme_bg rgb         Background color (default #000000)\n```\n\nCLI option and environment variable example:\n```shell\nuser@host $ MYAPP_LISTEN_IP=0.0.0.0 myapp --listen_port 80 --db_host localhost\nDB Host: localhost\nLog level: info\nIP: 0.0.0.0\nPort: 80\n```\n\nExample config yaml file:\n```yaml\nhostname: \"myapp.example.com\"\n\nlisten_ip: 0.0.0.0\nlisten_port: 80\n\nlog_level: info\n\ndb:\n  host: localhost\n  port: 5432\n  user: postgres\n  password: postgres\n\ntheme:\n  fg: \"#FF0000\"\n  bg: \"#000000\"\n```\n\nConfiguration values can be specified on the command line, using environment variables, and/or in a config file.\n\nConfigurature also supports\n\n* Custom types\n* Validation\n* Nested configurations\n\nSee the complete documentation at [http://configurature-docs.readthedocs.io](http://configurature-docs.readthedocs.io).\n\n\n## Templates\n\nPrint config file template:\n```shell\nuser@host $ myapp --print_yaml_template\n# Generated with\n# [--print_yaml_template]\n\n# hostname\nhostname: \"\"\n\n# read timeout\nread_timeout: 0\n\n# IP address on which to listen\nlisten_ip: 127.0.0.1\n\n# listen port\nlisten_port: 8080\n\ndb:\n\n  # db host\n  host: \"\"\n\n  # db port\n  port: 5432\n\n  # db user\n  user: postgres\n\n  # db password\n  password: postgres\n\n# log level (debug|info|warn|error)\nlog_level: info\n\ntheme:\n  # Foreground color\n  fg: \"#FFFFFF\"\n  # Background color\n  bg: \"#000000\"\n```\n\nPrint environment variable template:\n\n```shell\nuser@host $ myapp --print_env_template\n# Generated with\n# [--print_env_template]\n\n# Configuration file\nMYAPP_CONF=\"\"\n\n# db host\nMYAPP_DB_HOST=\"\"\n\n# db password\nMYAPP_DB_PASSWORD=\"postgres\"\n\n# db port\nMYAPP_DB_PORT=\"5432\"\n\n# db user\nMYAPP_DB_USER=\"postgres\"\n\n# hostname\nMYAPP_HOSTNAME=\"\"\n\n# IP address on which to listen\nMYAPP_LISTEN_IP=\"127.0.0.1\"\n\n# listen port\nMYAPP_LISTEN_PORT=\"8080\"\n\n# log level (debug|info|warn|error)\nMYAPP_LOG_LEVEL=\"info\"\n\n# read timeout\nMYAPP_READ_TIMEOUT=\"0\"\n\n# Foreground color\nMYAPP_THEME_FG=\"#FFFFFF\"\n\n# Background color\nMYAPP_THEME_BG=\"#000000\"\n```\n\nTemplates use existing values.\n\n```shell\nuser@host $ MYAPP_HOSTNAME=server1 myapp --print_yaml_template\n# Generated with\n# [--print_yaml_template]\n\n# hostname\nhostname: server1\n\n# read timeout\nread_timeout: 0\n\n# etc...\n```\n\n## Contributing\n\nSee [`CONTRIBUTING.md`](CONTRIBUTING.md) for details.                           \n\n## License \n\nApache 2.0; see [`LICENSE`](LICENSE) for details.                      \n\n## Disclaimer                                                                   \n\nThis project is not an official Google project. It is not supported by Google and Google specifically\ndisclaims all warranties as to its quality, merchantability, or fitness for a particular purpose.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimoore76%2Fconfigurature","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimoore76%2Fconfigurature","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimoore76%2Fconfigurature/lists"}