{"id":20534175,"url":"https://github.com/gookit/properties","last_synced_at":"2025-04-14T06:54:11.971Z","repository":{"id":48159858,"uuid":"515970389","full_name":"gookit/properties","owner":"gookit","description":"📝 Java Properties format contents parse, marshal and unmarshal library. Java Properties 格式内容的解析器，编码解码库","archived":false,"fork":false,"pushed_at":"2025-02-21T13:26:37.000Z","size":106,"stargazers_count":11,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-27T20:41:12.346Z","etag":null,"topics":["config","golang","java-properties","properties","properties-parser","text-parser"],"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/gookit.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":"2022-07-20T12:20:57.000Z","updated_at":"2025-02-21T13:26:32.000Z","dependencies_parsed_at":"2024-01-05T07:29:13.342Z","dependency_job_id":"c596fc2f-97af-4718-828c-86689437d15e","html_url":"https://github.com/gookit/properties","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":"inherelab/go-pkg-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gookit%2Fproperties","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gookit%2Fproperties/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gookit%2Fproperties/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gookit%2Fproperties/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gookit","download_url":"https://codeload.github.com/gookit/properties/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248837281,"owners_count":21169374,"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":["config","golang","java-properties","properties","properties-parser","text-parser"],"created_at":"2024-11-16T00:25:36.724Z","updated_at":"2025-04-14T06:54:11.950Z","avatar_url":"https://github.com/gookit.png","language":"Go","readme":"# Properties\n\n![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/gookit/properties?style=flat-square)\n[![Unit-Tests](https://github.com/gookit/properties/actions/workflows/go.yml/badge.svg)](https://github.com/gookit/properties/actions/workflows/go.yml)\n[![GitHub tag (latest SemVer)](https://img.shields.io/github/tag/gookit/properties)](https://github.com/gookit/properties)\n[![Go Report Card](https://goreportcard.com/badge/github.com/gookit/properties)](https://goreportcard.com/report/github.com/gookit/properties)\n[![Go Reference](https://pkg.go.dev/badge/github.com/gookit/properties.svg)](https://pkg.go.dev/github.com/gookit/properties)\n[![Coverage Status](https://coveralls.io/repos/github/gookit/properties/badge.svg?branch=master)](https://coveralls.io/github/gookit/properties?branch=master)\n\n`properties` - Java Properties format contents parse, marshal and unmarshal library.\n\n- Generic properties contents parser, marshal and unmarshal\n- Support `Marshal` and `Unmarshal` like `json` package\n- Support line comments start with `!`, `#`\n  - enhanced: allow `//`, `/* multi line comments */`\n- Support multi line string value, end with `\\\\`\n  - enhanced: allow `'''multi line string''''`, `\"\"\"multi line string\"\"\"`\n- Support value refer parse by var. format: `${some.other.key}`\n- Support ENV var parse. format: `${APP_ENV}`, `${APP_ENV | default}`\n\n\u003e **[中文说明](README.zh-CN.md)**\n\n## Install\n\n```shell\ngo get github.com/gookit/properties\n```\n\n## Usage\n\nExample `properties` contents:\n\n```properties\nname = inhere\nage = 345\nonly-key = \nenv-key = ${SHELL | bash}\n\n ##### comments1\ntop.sub.key0 = a string value\ntop.sub.key1 = \"a quote value1\"\ntop.sub.key2 = 'a quote value2'\n/* comments 1.1 */\ntop.sub.key3 = 234\n\n! inline list\ntop2.inline.list.ids = [234, 345, 456]\n\n# use var refer\ntop2.sub.var-refer = ${top.sub.key0}\n\n/*\nmulti line\ncomments\n*/\ntop2.sub.key2-other = has-char\n\n# comments 2\ntop.sub.key3 = false\n\n# slice list\ntop.sub.key4[0] = abc\ntop.sub.key4[1] = def\n\n## --- comments 3 ---\ntop.sub.key5[0].f1 = ab\ntop.sub.key5[1].f2 = de\n\n# multi line value\ntop.sub2.mline1 = \"\"\"multi line\nvalue\n\"\"\"\n\n# multi line value2\ntop.sub2.mline2 = this is \\\nmulti line2 \\\nvalue\n```\n\n## Parse to data\n\n```go\n  p := properties.NewParser(\n      properties.ParseEnv,\n      properties.ParseInlineSlice,\n  )\n  p.Parse(text)\n  fmt.Println(\"\\ndata map:\")\n  dump.NoLoc(p.Data)\n```\n\n**Output**:\n\n```shell\nmaputil.Data { #len=6\n  \"name\": string(\"inhere\"), #len=6\n  \"age\": string(\"345\"), #len=3\n  \"only-key\": string(\"\"), #len=0\n  \"env-key\": string(\"/bin/zsh\"), #len=8\n  \"top\": map[string]interface {} { #len=2\n    \"sub\": map[string]interface {} { #len=6\n      \"key5\": []map[string]interface {} [ #len=2\n        map[string]interface {} { #len=1\n          \"f1\": string(\"ab\"), #len=2\n        },\n        map[string]interface {} { #len=1\n          \"f2\": string(\"de\"), #len=2\n        },\n      ],\n      \"key0\": string(\"a string value\"), #len=14\n      \"key1\": string(\"a quote value1\"), #len=14\n      \"key2\": string(\"a quote value2\"), #len=14\n      \"key3\": string(\"false\"), #len=5\n      \"key4\": []string [ #len=2\n        string(\"abc\"), #len=3\n        string(\"def\"), #len=3\n      ],\n    },\n    \"sub2\": map[string]interface {} { #len=2\n      \"mline2\": string(\"this is multi line2 value\"), #len=25\n      \"mline1\": string(\"multi line\nvalue\n\"), #len=17\n    },\n  },\n  \"top2\": map[string]interface {} { #len=2\n    \"sub\": map[string]interface {} { #len=2\n      \"var-refer\": string(\"a string value\"), #len=14\n      \"key2-other\": string(\"has-char\"), #len=8\n    },\n    \"inline\": map[string]interface {} { #len=1\n      \"list\": map[string]interface {} { #len=1\n        \"ids\": []string [ #len=3\n          string(\"234\"), #len=3\n          string(\"345\"), #len=3\n          string(\"456\"), #len=3\n        ],\n      },\n    },\n  },\n},\n```\n\n## Parse and binding struct\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/gookit/properties\"\n)\n\nfunc Example() {\n\ttext := `\n# properties string\nname = inhere\nage = 200\n`\n\n\tp, err := properties.Parse(text)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\ttype MyConf struct {\n\t\tName string `properties:\"name\"`\n\t\tAge  int    `properties:\"age\"`\n\t}\n\n\tcfg := \u0026MyConf{}\n\terr = p.MapStruct(\"\", cfg)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(*cfg)\n\n\t// Output:\n\t// {inhere 200}\n}\n```\n\n## Marshal/Unmarshal\n\n- `Marshal(v any) ([]byte, error)`\n- `Unmarshal(v []byte, ptr any) error`\n\n**Example: Unmarshal**:\n\n```go\ncfg := \u0026MyConf{}\nerr := properties.Unmarshal([]byte(text), cfg)\nif err != nil {\n    panic(err)\n}\n\nfmt.Println(*cfg)\n```\n\n**Example: Marshal**\n\n```go\ndata := map[string]any{\n\t\"name\": \"inhere\",\n\t\"age\":  234,\n\t\"str1\": \"a string\",\n\t\"str2\": \"a multi \\nline string\",\n\t\"top\": map[string]any{\n\t\t\"sub0\": \"val0\",\n\t\t\"sub1\": []string{\"val1-0\", \"val1-1\"},\n\t},\n}\n\nbs, err = properties.Marshal(data)\nif err != nil {\n\tpanic(err)\n}\n\nfmt.Println(string(bs))\n```\n\nOutput:\n\n```properties\nstr1=a string\nstr2=a multi \\\nline string\ntop.sub1[0]=val1-0\ntop.sub1[1]=val1-1\ntop.sub0=val0\nname=inhere\nage=234\n```\n\n## Config management\n\nIf you want to support multiple formats and multiple file loading, it is recommended to use [gookit/config](https://github.com/gookit/config)\n\n- Support multi formats: `JSON`(default), `INI`, `Properties`, `YAML`, `TOML`, `HCL`\n- Support multi file loading and will auto merge loaded data\n\n## Gookit packages\n\n- [gookit/ini](https://github.com/gookit/ini) INI parse by golang. INI config data management library.\n- [gookit/rux](https://github.com/gookit/rux) Simple and fast request router, web framework for golang\n- [gookit/gcli](https://github.com/gookit/gcli) build CLI application, tool library, running CLI commands\n- [gookit/event](https://github.com/gookit/event) Lightweight event manager and dispatcher implements by Go\n- [gookit/cache](https://github.com/gookit/cache) Generic cache use and cache manager for golang. support File, Memory, Redis, Memcached.\n- [gookit/config](https://github.com/gookit/config) Go config management. support JSON, YAML, TOML, INI, HCL, ENV and Flags\n- [gookit/color](https://github.com/gookit/color) A command-line color library with true color support, universal API methods and Windows support\n- [gookit/filter](https://github.com/gookit/filter) Provide filtering, sanitizing, and conversion of golang data\n- [gookit/validate](https://github.com/gookit/validate) Use for data validation and filtering. support Map, Struct, Form data\n- [gookit/goutil](https://github.com/gookit/goutil) Some utils for the Go: string, array/slice, map, format, cli, env, filesystem, test and more\n- More, please see https://github.com/gookit\n\n## See also\n\n- Ini parse [gookit/ini/parser](https://github.com/gookit/ini/tree/master/parser)\n- Properties parse [gookit/properties](https://github.com/gookit/properties)\n\n## License\n\n**MIT**\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgookit%2Fproperties","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgookit%2Fproperties","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgookit%2Fproperties/lists"}