{"id":37128748,"url":"https://github.com/anhnmt/go-defaultconfig","last_synced_at":"2026-01-14T14:59:01.340Z","repository":{"id":282522423,"uuid":"948807636","full_name":"anhnmt/go-defaultconfig","owner":"anhnmt","description":"Go Configuration Loader with Default Values","archived":false,"fork":false,"pushed_at":"2025-03-29T15:30:14.000Z","size":30,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-14T16:38:05.919Z","etag":null,"topics":["default-value","go","golang","viper"],"latest_commit_sha":null,"homepage":"","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/anhnmt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2025-03-15T02:14:19.000Z","updated_at":"2025-03-29T15:30:17.000Z","dependencies_parsed_at":"2025-03-15T12:41:52.707Z","dependency_job_id":null,"html_url":"https://github.com/anhnmt/go-defaultconfig","commit_stats":null,"previous_names":["anhnmt/go-config","anhnmt/go-defaultconfig"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/anhnmt/go-defaultconfig","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anhnmt%2Fgo-defaultconfig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anhnmt%2Fgo-defaultconfig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anhnmt%2Fgo-defaultconfig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anhnmt%2Fgo-defaultconfig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anhnmt","download_url":"https://codeload.github.com/anhnmt/go-defaultconfig/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anhnmt%2Fgo-defaultconfig/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28424029,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T13:30:50.153Z","status":"ssl_error","status_checked_at":"2026-01-14T13:29:08.907Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5: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":["default-value","go","golang","viper"],"created_at":"2026-01-14T14:59:00.699Z","updated_at":"2026-01-14T14:59:01.327Z","avatar_url":"https://github.com/anhnmt.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DefaultConfig - Go Configuration Loader with Default Values\n\n`DefaultConfig` is a library for loading YAML configuration files and mapping data into a struct in Golang, using `Viper`. It supports environment variables and default values.\n\n## 🚀 Installation\n\nAdd the library to your project:\n```sh\ngo get -u github.com/anhnmt/go-defaultconfig\n```\n\n## 🛠️ Usage\n\n### 1️⃣ **Define the Configuration Struct**\n```go\ntype Config struct {\n    Name  string `mapstructure:\"name\" default:\"default_name\"`\n    Debug bool   `mapstructure:\"debug\" default:\"false\"`\n}\n```\n\n### 2️⃣ **Create a Configuration File** (e.g., `config/dev.yml`)\n```yaml\nname: \"my_app\"\ndebug: true\n```\n\n### 3️⃣ **Load Configuration with Load**\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"log\"\n)\n\nfunc main() {\n    var cfg Config\n    err := defaultconfig.Load(\"./config\", \"dev\", \u0026cfg)\n    if err != nil {\n        log.Fatalf(\"Error loading config: %v\", err)\n    }\n    fmt.Printf(\"Loaded config: %+v\\n\", cfg)\n}\n```\n\n## 🔧 Load Function Details\n```go\nfunc Load(dir, env string, cfg any) error\n```\n### ✅ **Parameters**\n- `dir`: Path to the directory containing the configuration files.\n- `env`: Environment name (corresponding to `config/{env}.yml`).\n- `cfg`: Pointer to the struct that receives the configuration data.\n\n### 🔄 **How It Works**\n1. **Determines the configuration file path** (`config/{env}.yml`).\n2. **Reads the YAML file** and maps it into `cfg`.\n3. **Supports environment variables** (converts `.` to `_`).\n4. **Supports default values** from the struct tag `default`.\n\n## ✅ Environment Variables Example\nIf environment variables are set:\n```sh\nexport NAME=\"env_name\"\nexport DEBUG=true\n```\nThe program will use these values instead of those in the YAML file.\n\n## 🧪 Running Unit Tests\n```sh\n# Run all tests\ngo test -v ./...\n```\n\n## 📜 License\nMIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanhnmt%2Fgo-defaultconfig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanhnmt%2Fgo-defaultconfig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanhnmt%2Fgo-defaultconfig/lists"}