{"id":15073716,"url":"https://github.com/hujun-open/shouchan","last_synced_at":"2026-02-13T14:38:30.782Z","repository":{"id":172062925,"uuid":"648805839","full_name":"hujun-open/shouchan","owner":"hujun-open","description":"a Golang module does simple configuration managment, support commandline and YAML file","archived":false,"fork":false,"pushed_at":"2025-01-31T23:48:31.000Z","size":61,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"v2","last_synced_at":"2025-02-01T00:25:08.105Z","etag":null,"topics":["command-line","configuration","golang","yaml"],"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/hujun-open.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-06-02T21:30:45.000Z","updated_at":"2025-01-31T23:48:34.000Z","dependencies_parsed_at":"2024-08-03T13:15:34.672Z","dependency_job_id":null,"html_url":"https://github.com/hujun-open/shouchan","commit_stats":null,"previous_names":["hujun-open/shouchan"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hujun-open%2Fshouchan","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hujun-open%2Fshouchan/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hujun-open%2Fshouchan/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hujun-open%2Fshouchan/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hujun-open","download_url":"https://codeload.github.com/hujun-open/shouchan/tar.gz/refs/heads/v2","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243864626,"owners_count":20360355,"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":["command-line","configuration","golang","yaml"],"created_at":"2024-09-25T03:04:27.924Z","updated_at":"2026-02-13T14:38:25.740Z","avatar_url":"https://github.com/hujun-open.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"![shouchan](./logo128.png)\n\n[![CI](https://github.com/hujun-open/shouchan/actions/workflows/main.yml/badge.svg)](https://github.com/hujun-open/shouchan/actions/workflows/main.yml)\n[![PkgGoDev](https://pkg.go.dev/badge/github.com/hujun-open/shouchan/v2)](https://pkg.go.dev/github.com/hujun-open/shouchan/v2)\n\n## Overview\nPackage shouchan provides simple configuration management for Golang application, with following features:\n\n  - read configuration from command line flag and/or YAML file, mix\u0026match, into a struct\n  - 3 sources: default value, YAML file and flag\n  - priority:in case of multiple source returns same config struct field, the preference is flag over YAML over default value\n\ninclude support following field types:\n- integer types\n- float type\n- string\n- time.Duration\n- and all types that implement `encoding.TextMarshaler` and `encoding.TextUnmarshaler` interface\n- there is also `github.com/hujun-open/shouchantypes` include some other types\n\nAdditional types could be supported by using `Register`, see [github.com/hujun-open/shouchantypes](https://github.com/hujun-open/shouchantypes) for example. \n\n## curent release is `github.com/hujun-open/shouchan/v2`\n\n## CLI \u0026 YAML Support\n\n- YAML: shouchan uses [extyaml](https://pkg.go.dev/github.com/hujun-open/extyaml) for YAML marshal and unmarshal \n- CLI Flag: shouchan uses [myflags](https://pkg.go.dev/github.com/hujun-open/myflags) for command line flag generation\n\nrefer to corresponding doc for details on CLI \u0026 YAML support. \n\n\n## Example:\nhttps://github.com/hujun-open/shouchan/blob/6d6eda8b423d48cd7461804b4beb5c7693b6c3ba/example/main.go#L1-L63\n\nOutput:\n\n- Usage\n```\t\n  .\\test.exe --help\nshouchan example\n\nUsage:\n  example [flags]\n\nFlags:\n      --addr string            employee address (default \"defAddrPointer\")\n      --cfgfromfile string     config file path (default \"test.yaml\")\n      --employer-name string   company name (default \"defCom\")\n  -h, --help                   help for example\n      --ipaddr net.IP          employee IP address (default 1.2.3.4)\n      --jointtime time.Time    employee join time (default 2023-01-02 13:22:33)\n      --mac net.HardwareAddr   employee MAC address (default 11:22:33:44:55:66)\n      --n2addr                  (default 1.1.1.1)\n      --naddr                   (default 2.2.2.2)\n      --name string            employee name (default \"defName\")\n      --r                      retired\n      --subnet net.IPNet       employee IP subnet (default 192.168.1.0/24)\nferr failed to open config file test.yaml, open test.yaml: The system cannot find the file specified.,aerr \u003cnil\u003e\nfinal result is \u0026{Name:defName Addr:0xc000028ee0 Naddr:2.2.2.2 N2addr:1.1.1.1 IPAddr:1.2.3.4 Subnet:{IP:192.168.1.0 Mask:ffffff00} MAC:11:22:33:44:55:66 JointTime:2023-01-02 13:22:33 +0000 UTC IsRetired:false Employer:{Name:defCom}}\n```    \n\n- no command line args, no config file, default is used\n```\n .\\test.exe   \nferr failed to open config file test.yaml, open test.yaml: The system cannot find the file specified.,aerr \u003cnil\u003e\nfinal result is \u0026{Name:defName Addr:0xc0000528b0 Naddr:2.2.2.2 N2addr:1.1.1.1 IPAddr:1.2.3.4 Subnet:{IP:192.168.1.0 Mask:ffffff00} MAC:11:22:33:44:55:66 JointTime:2023-01-02 13:22:33 +0000 UTC Employer:{Name:defCom}}\n```\n\n- config file via \"-f\" command args, value from file take procedence\n```\n .\\test.exe --cfgfromfile cfg.yaml\nferr \u003cnil\u003e,aerr \u003cnil\u003e\nfinal result is \u0026{Name:nameFromFile Addr:0xc0000528b0 Naddr:2.2.2.2 N2addr:1.1.1.1 IPAddr:1.2.3.4 Subnet:{IP:192.168.1.0 Mask:ffffff00} MAC:11:22:33:44:55:66 JointTime:2023-01-02 13:22:33 +0000 UTC Employer:{Name:comFromFile}}\n```\n- mix command line args and config file, args to override employee name:\n```\n.\\test.exe --cfgfromfile cfg.yaml --name nameFromArg\nferr \u003cnil\u003e,aerr \u003cnil\u003e\nfinal result is \u0026{Name:nameFromArg Addr:0xc000088880 Naddr:2.2.2.2 N2addr:1.1.1.1 IPAddr:1.2.3.4 Subnet:{IP:192.168.1.0 Mask:ffffff00} MAC:11:22:33:44:55:66 JointTime:2023-01-02 13:22:33 +0000 UTC Employer:{Name:comFromFile}}\n```\n- mix command line args and config file, args to override company name:\n```\n.\\test.exe --cfgfromfile cfg.yaml --employer-name comFromArg\nferr \u003cnil\u003e,aerr \u003cnil\u003e\nfinal result is \u0026{Name:nameFromFile Addr:0xc000104880 Naddr:2.2.2.2 N2addr:1.1.1.1 IPAddr:1.2.3.4 Subnet:{IP:192.168.1.0 Mask:ffffff00} MAC:11:22:33:44:55:66 JointTime:2023-01-02 13:22:33 +0000 UTC Employer:{Name:comFromArg}}\n```\n\n## Code Generation\nshouchan also provides a code generation tool to deal with large amount of constants, see [shouchangen](https://github.com/hujun-open/shouchangen).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhujun-open%2Fshouchan","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhujun-open%2Fshouchan","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhujun-open%2Fshouchan/lists"}