{"id":13693788,"url":"https://github.com/koding/multiconfig","last_synced_at":"2025-05-16T04:05:08.404Z","repository":{"id":19736506,"uuid":"22992936","full_name":"koding/multiconfig","owner":"koding","description":"Load configuration from multiple sources in Go","archived":false,"fork":false,"pushed_at":"2023-01-06T16:31:32.000Z","size":104,"stargazers_count":451,"open_issues_count":15,"forks_count":64,"subscribers_count":19,"default_branch":"master","last_synced_at":"2025-04-08T14:09:29.933Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://godoc.org/github.com/koding/multiconfig","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/koding.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":"2014-08-15T14:53:43.000Z","updated_at":"2025-03-04T10:43:51.000Z","dependencies_parsed_at":"2023-01-13T20:33:08.387Z","dependency_job_id":null,"html_url":"https://github.com/koding/multiconfig","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koding%2Fmulticonfig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koding%2Fmulticonfig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koding%2Fmulticonfig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koding%2Fmulticonfig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/koding","download_url":"https://codeload.github.com/koding/multiconfig/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254464895,"owners_count":22075570,"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-08-02T17:01:17.649Z","updated_at":"2025-05-16T04:05:08.389Z","avatar_url":"https://github.com/koding.png","language":"Go","funding_links":[],"categories":["开源类库","Open source library","Go"],"sub_categories":["配置","Construction"],"readme":"# Multiconfig [![GoDoc](https://godoc.org/github.com/koding/multiconfig?status.svg)](http://godoc.org/github.com/koding/multiconfig) [![Build Status](https://travis-ci.org/koding/multiconfig.svg?branch=master)](https://travis-ci.org/koding/multiconfig)\n\nLoad configuration from multiple sources. Multiconfig makes loading/parsing\nfrom different configuration sources an easy task. The problem with any app is\nthat with time there are many options how to populate a set of configs.\nMulticonfig makes it easy by dynamically creating all necessary options.\nCheckout the example below to see it in action.\n\n## Features\n\nMulticonfig is able to read configuration automatically based on the given struct's field names from the following sources:\n\n* Struct tags\n* TOML file\n* JSON file\n* YAML file\n* Environment variables\n* Flags\n\n\n## Install\n\n```bash\ngo get github.com/koding/multiconfig\n```\n\n## Usage and Examples\n\nLets define and struct that defines our configuration\n\n```go\ntype Server struct {\n\tName    string `required:\"true\"`\n\tPort    int    `default:\"6060\"`\n\tEnabled bool\n\tUsers   []string\n}\n```\n\nLoad the configuration into multiconfig:\n\n```go\n// Create a new DefaultLoader without or with an initial config file\nm := multiconfig.New()\nm := multiconfig.NewWithPath(\"config.toml\") // supports TOML, JSON and YAML\n\n// Get an empty struct for your configuration\nserverConf := new(Server)\n\n// Populated the serverConf struct\nerr := m.Load(serverConf) // Check for error\nm.MustLoad(serverConf)    // Panic's if there is any error\n\n// Access now populated fields\nserverConf.Port // by default 6060\nserverConf.Name // \"koding\"\n```\n\nRun your app:\n\n```sh\n# Sets default values first which are defined in each field tag value. \n# Starts to load from config.toml\n$ app\n\n# Override any config easily with environment variables, environment variables\n# are automatically generated in the form of STRUCTNAME_FIELDNAME\n$ SERVER_PORT=4000 SERVER_NAME=\"koding\" app\n\n# Or pass via flag. Flags are also automatically generated based on the field\n# name\n$ app -port 4000 -users \"gopher,koding\"\n\n# Print dynamically generated flags and environment variables:\n$ app -help\nUsage of app:\n  -enabled=true: Change value of Enabled.\n  -name=Koding: Change value of Name.\n  -port=6060: Change value of Port.\n  -users=[ankara istanbul]: Change value of Users.\n\nGenerated environment variables:\n   SERVER_NAME\n   SERVER_PORT\n   SERVER_ENABLED\n   SERVER_USERS\n```\n\n\n## License\n\nThe MIT License (MIT) - see [LICENSE](/LICENSE) for more details\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoding%2Fmulticonfig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkoding%2Fmulticonfig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoding%2Fmulticonfig/lists"}