{"id":42499874,"url":"https://github.com/linxlib/config","last_synced_at":"2026-01-28T13:03:45.624Z","repository":{"id":65752607,"uuid":"598455079","full_name":"linxlib/config","owner":"linxlib","description":null,"archived":false,"fork":false,"pushed_at":"2024-10-31T07:31:42.000Z","size":42,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-31T08:24:31.135Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/linxlib.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-02-07T06:20:41.000Z","updated_at":"2024-10-31T07:31:47.000Z","dependencies_parsed_at":"2024-06-20T05:40:04.936Z","dependency_job_id":"8b4867e8-c080-465f-8523-94c010b16ead","html_url":"https://github.com/linxlib/config","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/linxlib/config","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linxlib%2Fconfig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linxlib%2Fconfig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linxlib%2Fconfig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linxlib%2Fconfig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/linxlib","download_url":"https://codeload.github.com/linxlib/config/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linxlib%2Fconfig/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28845783,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-28T13:02:32.985Z","status":"ssl_error","status_checked_at":"2026-01-28T13:02:04.945Z","response_time":57,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":"2026-01-28T13:03:45.539Z","updated_at":"2026-01-28T13:03:45.609Z","avatar_url":"https://github.com/linxlib.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Config\n\nGolang Configuration tool that support YAML, JSON, Shell Environment\n\nis same as [configor](https://github.com/jinzhu/configor) , but add LoadWithKey support and remove toml\n\n## Usage\n\nconfig.example.yaml in `./config` directory\n\n```yaml\nserver:\n  host: 10.10.0.178\n  port: 8585\n\nredis:\n  host: 10.1.0.16\n  port: 6379\n  db: 5\n```\n\n```go\npackage main\n\nimport (\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"github.com/linxlib/config\"\n\t\"os\"\n)\n\ntype ServerConfig struct {\n\tHost string `yaml:\"host\" default:\"0.0.0.0\" env:\"CONFIG_HOST\"`\n\tPort string `yaml:\"port\" default:\"8080\"`\n}\n\ntype RedisConfig struct {\n\tHost string `yaml:\"host\" default:\"0.0.0.0\"`\n\tPort string `yaml:\"port\" default:\"8080\"`\n\tDB   int    `yaml:\"db\" default:\"0\"`\n}\n\nfunc main() {\n\t//os.Setenv(\"CONFIG_HOST\", \"1.1.1.1\")\n\tos.Setenv(\"CONFIG_REDIS_HOST\", \"1.2.1.1\")\n\tvar sc = new(ServerConfig)\n\tvar rc = new(RedisConfig)\n\terr := config.LoadWithKey(\"server\", sc, \"config/config.yaml\")\n\tif err != nil {\n\t\treturn\n\t}\n\terr = config.LoadWithKey(\"redis\", rc, \"config/config.yaml\")\n\tif err != nil {\n\t\treturn\n\t}\n\tvar sc1 = new(ServerConfig)\n\terr = config.LoadWithKey(\"\", sc1, \"config/config.yaml\")\n\tif err != nil {\n\t\treturn\n\t}\n\tbs, _ := json.MarshalIndent(sc, \"\", \"  \")\n\tfmt.Println(string(bs))\n\tbs, _ = json.MarshalIndent(rc, \"\", \"  \")\n\tfmt.Println(string(bs))\n\tbs, _ = json.MarshalIndent(sc1, \"\", \"  \")\n\tfmt.Println(string(bs))\n\n}\n```\n\nWith configuration file *config.yml*:\n\n```yaml\nappname: test\n\ndb:\n    name:     test\n    user:     test\n    password: test\n    port:     1234\n\ncontacts:\n- name: i test\n  email: test@test.com\n```\n\n## Debug Mode \u0026 Verbose Mode\n\nDebug/Verbose mode is helpful when debuging your application, `debug mode` will let you know how `config` loaded your configurations, like from which file, shell env, `verbose mode` will tell you even more, like those shell environments `config` tried to load.\n\n```go\n// Enable debug mode or set env `CONFIG_DEBUG_MODE` to true when running your application\nconfig.New(\u0026config.Config{Debug: true}).Load(\u0026Config, \"config.json\")\n\n// Enable verbose mode or set env `CONFIG_VERBOSE_MODE` to true when running your application\nconfig.New(\u0026config.Config{Verbose: true}).Load(\u0026Config, \"config.json\")\n```\n\n## Auto Reload Mode\n\nConfig can auto reload configuration based on time\n\n```go\n// auto reload configuration every second\nconfig.New(\u0026config.Config{AutoReload: true}).Load(\u0026Config, \"config.json\")\n\n// auto reload configuration every minute\nconfig.New(\u0026config.Config{AutoReload: true, AutoReloadInterval: time.Minute}).Load(\u0026Config, \"config.json\")\n```\n\nAuto Reload Callback\n\n```go\nconfig.New(\u0026config.Config{AutoReload: true, AutoReloadCallback: func(config interface{}) {\n    fmt.Printf(\"%v changed\", config)\n}}).Load(\u0026Config, \"config.json\")\n```\n\n# Advanced Usage\n\n* Load multiple configurations\n\n```go\n// Earlier configurations have higher priority\nconfig.Load(\u0026Config, \"application.yml\", \"database.json\")\n```\n\n* Load configuration by environment\n\nUse `CONFIG_ENV` to set environment, if `CONFIG_ENV` not set, environment will be `development` by default, and it will be `test` when running tests with `go test`\n\n```go\n// config.go\nconfig.Load(\u0026Config, \"config.json\")\n\n$ go run config.go\n// Will load `config.json`, `config.development.json` if it exists\n// `config.development.json` will overwrite `config.json`'s configuration\n// You could use this to share same configuration across different environments\n\n$ CONFIG_ENV=production go run config.go\n// Will load `config.json`, `config.production.json` if it exists\n// `config.production.json` will overwrite `config.json`'s configuration\n\n$ go test\n// Will load `config.json`, `config.test.json` if it exists\n// `config.test.json` will overwrite `config.json`'s configuration\n\n$ CONFIG_ENV=production go test\n// Will load `config.json`, `config.production.json` if it exists\n// `config.production.json` will overwrite `config.json`'s configuration\n```\n\n```go\n// Set environment by config\nconfig.New(\u0026config.Config{Environment: \"production\"}).Load(\u0026Config, \"config.json\")\n```\n\n* Example Configuration\n\n```go\n// config.go\nconfig.Load(\u0026Config, \"config.yml\")\n\n$ go run config.go\n// Will load `config.example.yml` automatically if `config.yml` not found and print warning message\n```\n\n* Load From Shell Environment\n\n```go\n$ CONFIG_APPNAME=\"hello world\" CONFIG_DB_NAME=\"hello world\" go run config.go\n// Load configuration from shell environment, it's name is {{prefix}}_FieldName\n```\n\n```go\n// You could overwrite the prefix with environment CONFIG_ENV_PREFIX, for example:\n$ CONFIG_ENV_PREFIX=\"WEB\" WEB_APPNAME=\"hello world\" WEB_DB_NAME=\"hello world\" go run config.go\n\n// Set prefix by config\nconfig.New(\u0026config.Config{ENVPrefix: \"WEB\"}).Load(\u0026Config, \"config.json\")\n```\n\n* Anonymous Struct\n\nAdd the `anonymous:\"true\"` tag to an anonymous, embedded struct to NOT include the struct name in the environment\nvariable of any contained fields.  For example:\n\n```go\ntype Details struct {\n\tDescription string\n}\n\ntype Config struct {\n\tDetails `anonymous:\"true\"`\n}\n```\n\nWith the `anonymous:\"true\"` tag specified, the environment variable for the `Description` field is `CONFIG_DESCRIPTION`.\nWithout the `anonymous:\"true\"`tag specified, then environment variable would include the embedded struct name and be `CONFIG_DETAILS_DESCRIPTION`.\n\n* With flags\n\n```go\nfunc main() {\n\tconf := flag.String(\"file\", \"config.yml\", \"configuration file\")\n\tflag.StringVar(\u0026Config.APPName, \"name\", \"\", \"app name\")\n\tflag.StringVar(\u0026Config.DB.Name, \"db-name\", \"\", \"database name\")\n\tflag.StringVar(\u0026Config.DB.User, \"db-user\", \"root\", \"database user\")\n\tflag.Parse()\n\n\tos.Setenv(\"CONFIG_ENV_PREFIX\", \"-\")\n\tconfig.Load(\u0026Config, *conf)\n\t// config.Load(\u0026Config) // only load configurations from shell env \u0026 flag\n}\n```\n\n\n\n## License\n\nReleased under the MIT License","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinxlib%2Fconfig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flinxlib%2Fconfig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinxlib%2Fconfig/lists"}