{"id":13411104,"url":"https://github.com/wlevene/ini","last_synced_at":"2026-01-30T20:09:14.527Z","repository":{"id":57623050,"uuid":"395642448","full_name":"wlevene/ini","owner":"wlevene","description":"ini parser for golang","archived":false,"fork":false,"pushed_at":"2023-07-14T02:56:32.000Z","size":98,"stargazers_count":15,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-07-30T20:38:53.477Z","etag":null,"topics":["ast","config","configuration","golang","ini","ini-parser","inifile"],"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/wlevene.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}},"created_at":"2021-08-13T12:13:44.000Z","updated_at":"2024-06-23T06:05:22.000Z","dependencies_parsed_at":"2024-01-08T14:30:55.790Z","dependency_job_id":"c8cf525d-f8ae-4941-a595-a6dd62490e34","html_url":"https://github.com/wlevene/ini","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/wlevene/ini","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wlevene%2Fini","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wlevene%2Fini/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wlevene%2Fini/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wlevene%2Fini/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wlevene","download_url":"https://codeload.github.com/wlevene/ini/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wlevene%2Fini/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28918235,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-30T19:10:10.838Z","status":"ssl_error","status_checked_at":"2026-01-30T19:06:40.573Z","response_time":66,"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":["ast","config","configuration","golang","ini","ini-parser","inifile"],"created_at":"2024-07-30T20:01:11.430Z","updated_at":"2026-01-30T20:09:14.510Z","avatar_url":"https://github.com/wlevene.png","language":"Go","funding_links":[],"categories":["配置","Configuration","Uncategorized"],"sub_categories":["标准CLI","Standard CLI","Advanced Console UIs"],"readme":"\n\n![logo](./logo.png)\n\n#  INI Parser \u0026 Reader Writer Library\n\n## Introduction\n\nThe INI Parser \u0026 Reader Writer Library is a fast and easy-to-use library for parsing and manipulating INI files in the Go programming language. It provides functionality to read INI files from both byte slices and files, supports real-time file monitoring, and offers options to unmarshal INI data into Go structs, marshal data to JSON, and write data back to files.\n\n\n[![Build Status](https://travis-ci.org/meolu/walden.svg?branch=master)](https://github.com/wlevene/ini)\n![version](https://img.shields.io/badge/version-0.1.5-blue)\n[![Go Report Card](https://goreportcard.com/badge/github.com/wlevene/ini)](https://goreportcard.com/report/github.com/wlevene/ini)\n[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge-flat.svg)](https://github.com/avelino/awesome-go)\n\n## Features\n* **Read by []byte**: The library allows you to parse INI data stored in a byte slice.\n* **Read by file**: You can also read INI data directly from a file.\n* **Real-time file monitoring**: The library supports file monitoring, allowing you to observe changes in INI files without the need for manual reloading.\n* **Unmarshal to Struct**: It provides the ability to map INI data to Go structs, making it convenient to work with structured data.\n* **Marshal to JSON**: You can easily convert INI data to JSON format using the library's marshal functionality.\n* **Write to File**: The library allows you to write INI data back to files, preserving the original file format.\n\n\n## Installation\n\n```shell\ngo get github.com/wlevene/ini\n```\n\n\n## Example\n\n```go\nimport (\n    \"fmt\"\n    \"github.com/wlevene/ini\"\n)\n```\n\n### GetValue\n\n```go\ndoc := `\n[section]\nk=v\n\n[section1]\nk1=v1\nk2=1\nk3=3.5\nk4=0.0.0.0\n`\nv1 := ini.New().Load([]byte(doc)).Section(\"section1\").Get(\"k1\")\nfmt.Println(v1)\n```\n\nOutput\n\n```\nv1\n```\n\n\n```go\ni := ini.New().Load([]byte(doc))\nv1 := i.Section(\"section1\").Get(\"k1\")\nv2 := i.GetInt(\"k2\")\nv3 := i.GetFloat64(\"k3\")\nv4 := i.Get(\"k4\")\nv5 := i.GetIntDef(\"keyint\", 10)\nv6 := i.GetDef(\"keys\", \"defualt\")\n\nfmt.Printf(\"v1:%v v2:%v v3:%v v4:%v v5:%v v6:%v\\n\", v1, v2, v3, v4, v5, v6)\n```\n\nOutput\n\n```\nv1:v1 v2:1 v3:3.5 v4:0.0.0.0 v5:10 v6:defualt\n```\n\n\n### Marshal2Json\n\n```go\nfmt.Println(string(i.Marshal2Json()))\n```\n\nOutput\n\n```json\n{\"section\":{\"k\":\"v\"},\"section1\":{\"k1\":\"v1\",\"k2\":\"1\",\"k3\":\"3.5\",\"k4\":\"0.0.0.0\"}}\n```\n\n### Unmarshal Struct\n\n```go\ntype TestConfig struct {\n\tK    string  `ini:\"k\" json:\"k,omitempty\"`\n\tK1   int     `ini:\"k1\" json:\"k1,omitempty\"`\n\tK2   float64 `ini:\"k2\"`\n\tK3   int64   `ini:\"k3\"`\n\tUser User    `ini:\"user\"`\n}\n\ntype User struct {\n\tName string `ini:\"name\"`\n\tAge  int    `ini:\"age\"`\n}\n\n```\n\n```go\ndoc := `\nk=v\nk1=2\nk2=2.2\nk3=3\n\n[user]\nname=tom\nage=-23\n`\n\ncfg := TestConfig{}\n\nini.Unmarshal([]byte(doc), \u0026cfg)\nfmt.Println(\"cfg:\", cfg)\n```\n\nOutput\n\n```\ncfg: {v 2 2.2 3 {tom -23}}\n```\n\n\n\n### Parse File\n\nini file\n\n```ini\n; this is comment\n; author levene \n; date 2021-8-1\n\n\na='23'34?::'\u003c\u003e,.'\nc=d\n\n[s1]\nk=67676\nk1 =fdasf \nk2= sdafj3490\u0026@)34 34w2\n\n# comment \n# 12.0.0.1\n[s2]\n\nk=3\n\n\nk2=945\nk3=-435\nk4=0.0.0.0\n\nk5=127.0.0.1\nk6=levene@github.com\n\nk7=~/.path.txt\nk8=./34/34/uh.txt\n\nk9=234@!@#$%^\u0026*()324\nk10='23'34?::'\u003c\u003e,.'\n\n```\n\n```go\nfile := \"./test.ini\"\nini.New().LoadFile(file).Section(\"s2\").Get(\"k2\")\n\nfmt.Println(string(ini.Marshal2Json()))\n```\n\nOutput\n\n```\n945\n```\n\n\n\n### Watch File\n\n```go\nfile := \"./test.ini\"\n\nidoc := ini.New().WatchFile(file)\nv := idoc.Section(\"s2\").Get(\"k1\")\nfmt.Println(\"v:\", v1)\n\n// modify k1=v1   ==\u003e k1=v2\ntime.Sleep(10 * time.Second)\n\nv = idoc.Section(\"s2\").Get(\"k1\")\nfmt.Println(\"v:\", v1)\n```\n\nOutput\n\n```\nv: v1\nv: v2\n```\n\n\n\nPrint file with json\n\n```go\nfile := \"./test.ini\"\nfmt.Println(string(ini.New().LoadFile(file).Marshal2Json()))\n```\n\nOutput\n\n```json\n{\n  \"a\": \"'23'34?::'\u003c\u003e,.'\",\n  \"c\": \"d\",\n  \"s1\": {\n    \"k\": \"67676\",\n    \"k2\": \"34w2\"\n  },\n  \"s2\": {\n    \"k\": \"3\",\n    \"k10\": \"'23'34?::'\u003c\u003e,.'\",\n    \"k2\": \"945\",\n    \"k3\": \"-435\",\n    \"k4\": \"0.0.0.0\",\n    \"k5\": \"127.0.0.1\",\n    \"k6\": \"levene@github.com\",\n    \"k7\": \"~/.path.txt\",\n    \"k8\": \"./34/34/uh.txt\",\n    \"k9\": \"234@!@#$%^\u0026*()324\"\n  }\n}\n```\n\n### Set Ini \n```go\ndoc := `\nk =v\n[section]\na=b\nc=d\n`\nini := New().Load([]byte(doc)).Section(\"section\")\nfmt.Println(\"--------------------------------\")\nini.Dump()\n\nfmt.Println(\"--------------------------------\")\nini.Set(\"a\", 11).Set(\"c\", 12.3).Section(\"\").Set(\"k\", \"SET\")\nini.Dump()\n\nv := ini.Section(\"section\").GetInt(\"a\")\n\nif v != 11 {\n    t.Errorf(\"Error: %d\", v)\n}\n\nv1 := ini.GetFloat64(\"c\")\n\nif v1 != 12.3 {\n    t.Errorf(\"Error: %f\", v1)\n}\n\nv2 := ini.Section(\"\").Get(\"k\")\nif v2 != \"SET\" {\n    t.Errorf(\"Error: %s\", v2)\n}\n```\n\n\n\n### Wirte Ini\n\n```go\nfilename := \"./save.ini\"\nini := New().Set(\"a1\", 1)\nini.Save(filename)\nfmt.Println(ini.Err())\n\nini2 := New().Set(\"a1\", 1).Section(\"s1\").Set(\"a2\", \"v2\")\nini2.Save(filename)\nfmt.Println(ini2.Err())\n\n// ------\n\ndoc := `\n; 123\nc11=d12312312\n# 434\n\n[section]\nk=v\n; dsfads \n;123\n#3452345\n\n\n[section1]\nk1=v1\n\n[section3]\nk3=v3\n`\nini3 := New().Load([]byte(doc))\nini.Save(\"./save.ini\")\n\n```\n\nfile content\n```ini\n\n; 123\nc11 = d12312312\n\n# 434\n[section]\nk = v\n\n; dsfads \n;123\n#3452345\n[section1]\nk1 = v1\n\n[section3]\nk3 = v3\n\n```\n\n\n\n### Dump AST struct\n\n```\nINIDocNode {\n    CommentNode {\n        Comment: ; this is comment\n        Line: 0\n    }\n    CommentNode {\n        Comment: ; author levene\n        Line: 1\n    }\n    CommentNode {\n        Comment: ; date 2021-8-1\n        Line: 2\n    }\n    KVNode {\n        Key: a\n        Value: '23'34?::'\u003c\u003e,.'\n        Line: 5\n    }\n    KVNode {\n        Key: c\n        Value: d\n        Line: 6\n    }\n    Section {\n        Section: [s1]\n        Line: 8\n        KVNode {\n            Value: 67676\n            Line: 9\n            Key: k\n        }\n        KVNode {\n            Key: k1\n            Value: fdasf\n            Line: 10\n        }\n        KVNode {\n            Value: 4w2\n            Line: 11\n            Key: k2\n        }\n    }\n    CommentNode {\n        Comment: # comment\n        Line: 13\n    }\n    CommentNode {\n        Line: 14\n        Comment: # 12.0.0.1\n    }\n    Section {\n        Section: [s2]\n        Line: 15\n        KVNode {\n            Value: 3\n            Line: 17\n            Key: k\n        }\n        KVNode {\n            Value: 945\n            Line: 20\n            Key: k2\n        }\n        KVNode {\n            Key: k3\n            Value: -435\n            Line: 21\n        }\n        KVNode {\n            Line: 22\n            Key: k4\n            Value: 0.0.0.0\n        }\n        KVNode {\n            Line: 24\n            Key: k5\n            Value: 127.0.0.1\n        }\n        KVNode {\n            Key: k6\n            Value: levene@github.com\n            Line: 25\n        }\n        KVNode {\n            Key: k7\n            Value: ~/.path.txt\n            Line: 27\n        }\n        KVNode {\n            Line: 28\n            Key: k8\n            Value: ./34/34/uh.txt\n        }\n        KVNode {\n            Key: k9\n            Value: 234@!@#$%^\u0026*()324\n            Line: 30\n        }\n        KVNode {\n            Key: k10\n            Value: '23'34?::'\u003c\u003e,.'\n            Line: 31\n        }\n    }\n}\n```\n\n## License\n\n[MIT](https://github.com/RichardLitt/standard-readme/blob/master/LICENSE)  \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwlevene%2Fini","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwlevene%2Fini","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwlevene%2Fini/lists"}