{"id":43293199,"url":"https://github.com/vanhtuan0409/copperhead","last_synced_at":"2026-02-01T18:35:35.773Z","repository":{"id":99957250,"uuid":"265759461","full_name":"vanhtuan0409/copperhead","owner":"vanhtuan0409","description":"A wrapper around spf13/viper and spf13/pflag with opinionted interface.","archived":false,"fork":false,"pushed_at":"2020-05-21T07:36:30.000Z","size":26,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-06-20T06:38:41.835Z","etag":null,"topics":["12-factor","cli","config","go","pflags","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/vanhtuan0409.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":"2020-05-21T05:06:46.000Z","updated_at":"2020-05-22T03:26:11.000Z","dependencies_parsed_at":"2023-03-13T15:43:20.575Z","dependency_job_id":null,"html_url":"https://github.com/vanhtuan0409/copperhead","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/vanhtuan0409/copperhead","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vanhtuan0409%2Fcopperhead","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vanhtuan0409%2Fcopperhead/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vanhtuan0409%2Fcopperhead/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vanhtuan0409%2Fcopperhead/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vanhtuan0409","download_url":"https://codeload.github.com/vanhtuan0409/copperhead/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vanhtuan0409%2Fcopperhead/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28985818,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-01T18:17:03.387Z","status":"ssl_error","status_checked_at":"2026-02-01T18:16:57.287Z","response_time":56,"last_error":"SSL_read: 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":["12-factor","cli","config","go","pflags","viper"],"created_at":"2026-02-01T18:35:35.084Z","updated_at":"2026-02-01T18:35:35.766Z","avatar_url":"https://github.com/vanhtuan0409.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Copperhead\n\nA wrapper around [spf13/viper](https://github.com/spf13/viper) and [spf13/pflag](https://github.com/spf13/pflag) with opinionted interface.\n\n[![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go\u0026logoColor=white\u0026style=flat-square)](https://pkg.go.dev/github.com/vanhtuan0409/copperhead)\n\n### Installation\n\nInstall by running:\n\n```\ngo get -u github.com/vanhtuan0409/copperhead\n```\n\n### Usage\n\nCopperhead support unmarshal struct using values from\n\n- Command line args\n- Environment variables\n- Config file\n\nExample usage:\n\n```go\npackage main\n\nimport (\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"reflect\"\n\t\"time\"\n\n\t\"github.com/vanhtuan0409/copperhead\"\n)\n\ntype Config struct {\n\tHttpPort int           `mapstructure:\"http_port\" cli:\"port\" default:\"8080\" description:\"HTTP binding port\"`\n\tTimeout  time.Duration `mapstructure:\"timeout\" default:\"5s\" description:\"HTTP request timeout\"`\n}\n\nfunc (c *Config) String() string {\n\ts, _ := json.MarshalIndent(c, \"\", \"\\t\")\n\treturn string(s)\n}\n\nfunc main() {\n\tcfg := Config{}\n\tcopperhead.Unmarshal(\u0026cfg, reflect.TypeOf(cfg), copperhead.ConfigOptions{})\n\tfmt.Println(cfg.String())\n}\n```\n\nCLI Help:\n\n```\n$ go run main.go -h\nUsage of /tmp/go-build191072962/b001/exe/main:\n      --config string    Path to config file (default \"config.yaml\")\n      --port string      HTTP binding port (default \"8080\")\n      --timeout string   HTTP request timeout (default \"5s\")\npflag: help requested\nexit status 2\n```\n\n### Config\n\nCopperhead provide 3 struct tags:\n\n- **mapstructure**: key for configuration. Example: `mapstructure:\"http_port\"` will be intepreted as env var `HTTP_PORT` and cli args `--http-port`\n  - Enviroment variable will be translated as upper case\n  - CLI args will be translated as `strings.ReplaceAll(keyPath, \"_\", \"-\")`\n- **default**: default value of this field. If cannot be coerce to target type, copperhead will panic\n- **cli**: name of CLI args. If not defined, CLI args will be intepreted from mapstructure\n- **description**: CLI args description\n\n#### Nested struct\n\nNested struct will be key path will be intepreted with `.` for cli args and `__` for env var\n\nExample:\n```\ntype Config struct {\n\tNestedStruct struct {\n\t\tMyNumber int `mapstructure:\"my_number\" default:\"10\"`\n\t} `mapstructure:\"nested_struct\"`\n}\n```\n\nWill be intepreted as:\n\n```yaml\n# Yaml file\nnested_struct:\n  my_number: 10\n```\n\n```sh\n$ go run main.go -h\nUsage of /tmp/go-build793598133/b001/exe/main:\n      --config string                    Path to config file (default \"config.yaml\")\n      --nested-struct.my-number string    (default \"10\")\npflag: help requested\nexit status 2\n```\n\nAnd environment variable `NESTED_STRUCT__MY_NUMBER`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvanhtuan0409%2Fcopperhead","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvanhtuan0409%2Fcopperhead","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvanhtuan0409%2Fcopperhead/lists"}