{"id":24668862,"url":"https://github.com/linuxerwang/confish","last_synced_at":"2025-03-21T13:25:07.652Z","repository":{"id":36877136,"uuid":"41184117","full_name":"linuxerwang/confish","owner":"linuxerwang","description":"A config parser in golang for Confish Configuration Format","archived":false,"fork":false,"pushed_at":"2023-03-14T00:33:02.000Z","size":14,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-26T09:17:45.420Z","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":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/linuxerwang.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":"2015-08-22T01:01:42.000Z","updated_at":"2021-01-21T10:00:57.000Z","dependencies_parsed_at":"2022-09-07T05:30:48.539Z","dependency_job_id":null,"html_url":"https://github.com/linuxerwang/confish","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/linuxerwang%2Fconfish","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linuxerwang%2Fconfish/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linuxerwang%2Fconfish/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linuxerwang%2Fconfish/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/linuxerwang","download_url":"https://codeload.github.com/linuxerwang/confish/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244804632,"owners_count":20513148,"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":"2025-01-26T09:17:48.341Z","updated_at":"2025-03-21T13:25:07.627Z","avatar_url":"https://github.com/linuxerwang.png","language":"Go","readme":"# confish\nA config parser in golang for Confish Configuration Format.\n\n## Install\n\nTo update the generated cfg.go (optional):\n\n```bash\n$ go tool yacc -o cfg.go -p Cfg cfg.y\n```\n\nGo get confish:\n\n```bash\n$ go get github.com/linuxerwang/confish\n```\n\n## Parse confish file\n\n```go\nimport \"github.com/linuxerwang/confish\"\n\ntype MyConf struct {\n\t...\n}\n\nconf := \u0026MyConf{}\nerr := confish.ParseFile(\"path/to/myconf.conf\", conf)\n...\n```\n\n## Write confish file\n\n```go\nimport \"github.com/linuxerwang/confish\"\n\ntype MyConf struct {\n\t...\n}\n\nconf := \u0026MyConf{}\nerr := confish.WriteFile(\"path/to/myconf.conf\", conf, \"my-conf\")\n...\n```\n\n## The Confish Configuration Format\n\nA confish file maps to a Go struct directly through the Go struct field tags.\n\nIn Go:\n```go\ntype Book struct {\n\tName string `cfg-attr:\"name\"`\n\tISBN string `cfg-attr:\"isbn\"`\n}\n```\n\nIn config file:\n```\nbook {\n\tname: \"The way to Go\"\n\tisbn: \"123456789\"\n}\n```\n\nThe confish parser uses the \"cfg-attr\" tags to locate the corresponding fields\nin structs. Confish supports primitive types and collection types.\n\nTo specify a field of struct type:\n\n```\n\tname {\n\t\t...\n\t}\n```\n\nTo specify a field of slice of struct:\n\n```\n\tname {\n\t\t...\n\t}\n\n\tname {\n\t\t...\n\t}\n\n\tname {\n\t\t...\n\t}\n```\n\nTo specify a normal field:\n\n```\n\tname: value\n```\n\nPrimitive types: string, int, int32, int64, float32, float64, bool.\nCollection types: slice of primitives, map of primitives.\n\nConfish supports two types of slices: simple slice and struct slice.\n\nElements in simple slice must be primitive types.\nElements in struct slice must be struct types.\n\nKeys in map must be int, int32, int64, or string.\nValues in map must be int, int32, int64, bool, or string.\n\nComments start with \"#\" and stop at the end of line.\n\n### Examples\n\n*Example for embedded structs*\n\n```go\ntype DisplayInfo struct {\n\tModel string `cfg-attr:\"model\"`\n\tSize  string `cfg-attr:\"size\"`\n}\n\ntype KeyboardInfo struct {\n\tKeyCount int    `cfg-attr:\"key-count\"`\n\tLayout   string `cfg-attr:\"key-layout\"`\n}\n\ntype Laptop struct {\n\tDI DisplayInfo  `cfg-attr:\"display\"`\n\tKI KeyboardInfo `cfg-attr:\"keyboard\"`\n}\n```\n\n```\nlaptop {\n\tdisplay {\n\t\tmodel: \"Dell 1234\"\n\t\tsize: \"1920x1080\"\n\t}\n\n\tkeyboard {\n\t\tkey-count: 87\n\t\tkey-layout: \"compact\"\n\t}\n}\n```\n\n*Example for simple slice*\n\n```go\ntype Router struct {\n\tWhitelist []string `cfg-attr:\"whitelist\"`\n\tBlacklist []string `cfg-attr:\"blacklist\"`\n}\n```\n\n```\nrouter {\n\twhitelist: [\n\t\t\"http://www.google.com\",\n\t\t\"http://www.amazon.com\",\n\t\t\"http://www.twitter.com\",\n\t]\n\tblacklist: [\n\t\t\"http://www.test.com\",\n\t\t\"http://www.fishing.com\",\n\t]\n}\n```\n\n*Example for slice of structs*\n\n```go\ntype BookShelf struct {\n\tCategory string  `cfg-attr:\"category\"`\n\tBooks    []*Book `cfg-attr:\"book\"`\n}\n```\n\n```\nbookshelf {\n\tcategory: \"Computer Technology\"\n\n\tbook {\n\t\tname: \"The way to Go\"\n\t\tisbn: \"123456789\"\n\t}\n\n\tbook {\n\t\tname: \"The Go Programming Language\"\n\t\tisbn: \"987654321\"\n\t}\n}\n```\n\n*Example for maps*\n\n```go\ntype PriceMap struct {\n\tPrices map[string]float32 `cfg-attr:\"prices\"`\n}\n```\n\n```\nprice-map {\n\tprices: {\n\t\t\"Red\": 12.49,\n\t\t\"Green\": 10.99,\n\t\t\"Blue\": 13.99,\n\t}\n}\n```\n\n*Example for deep struct nesting*\n\n```go\ntype A struct {\n\tName string `cfg-attr:\"name\"`\n}\n\ntype B struct {\n\tARef A `cfg-attr:\"a\"`\n}\n\ntype C struct {\n\tBRef B `cfg-attr:\"b\"`\n}\n\ntype D struct {\n\tCRef C `cfg-attr:\"c\"`\n}\n\n```\n\n```\nd {\n\tc {\n\t\tb {\n\t\t\ta {\n\t\t\t\tname: \"John Doe\"\n\t\t\t}\n\t\t}\n\t}\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinuxerwang%2Fconfish","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flinuxerwang%2Fconfish","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinuxerwang%2Fconfish/lists"}