{"id":20534188,"url":"https://github.com/gookit/ini","last_synced_at":"2025-04-04T18:07:22.068Z","repository":{"id":37550395,"uuid":"141389657","full_name":"gookit/ini","owner":"gookit","description":"📝 Go INI config management. support multi file load, data override merge. parse ENV variable, parse variable reference. Dotenv file parse and loader. INI配置读取管理，支持多文件加载，数据覆盖合并, 解析ENV变量, 解析变量引用。DotEnv 解析加载","archived":false,"fork":false,"pushed_at":"2024-12-10T01:53:15.000Z","size":294,"stargazers_count":84,"open_issues_count":1,"forks_count":17,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-28T17:08:20.694Z","etag":null,"topics":["config","configuration","configuration-management","dotenv","dotenv-loader","env","environment","environment-variables","golang","ini","ini-config","ini-parser"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/gookit/ini/v2","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":"2018-07-18T06:16:28.000Z","updated_at":"2025-02-01T18:55:45.000Z","dependencies_parsed_at":"2024-03-12T04:30:18.067Z","dependency_job_id":"69d652a6-a9f1-4d0a-a005-bb617ff42a8e","html_url":"https://github.com/gookit/ini","commit_stats":{"total_commits":213,"total_committers":8,"mean_commits":26.625,"dds":0.3943661971830986,"last_synced_commit":"1bfbdeb1486f2db643e6d8d55928d025311bac73"},"previous_names":[],"tags_count":34,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gookit%2Fini","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gookit%2Fini/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gookit%2Fini/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gookit%2Fini/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gookit","download_url":"https://codeload.github.com/gookit/ini/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247226213,"owners_count":20904465,"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","configuration","configuration-management","dotenv","dotenv-loader","env","environment","environment-variables","golang","ini","ini-config","ini-parser"],"created_at":"2024-11-16T00:25:39.992Z","updated_at":"2025-04-04T18:07:22.050Z","avatar_url":"https://github.com/gookit.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# INI\n\n![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/gookit/ini?style=flat-square)\n[![GitHub tag (latest SemVer)](https://img.shields.io/github/tag/gookit/ini)](https://github.com/gookit/ini)\n[![Coverage Status](https://coveralls.io/repos/github/gookit/ini/badge.svg?branch=master)](https://coveralls.io/github/gookit/ini?branch=master)\n[![Go Report Card](https://goreportcard.com/badge/github.com/gookit/ini)](https://goreportcard.com/report/github.com/gookit/ini)\n[![Unit-Tests](https://github.com/gookit/ini/actions/workflows/go.yml/badge.svg)](https://github.com/gookit/ini)\n[![Go Reference](https://pkg.go.dev/badge/github.com/gookit/ini/v2.svg)](https://pkg.go.dev/github.com/gookit/ini/v2)\n\n`INI` contents parser by Golang, `INI` config data management.\n\n\u003e **[中文说明](README.zh-CN.md)**\n\n## Features\n\n- Easy to use(get: `Int` `Int64` `Bool` `String` `StringMap` ..., set: `Set`)\n- Support multi file, data load\n- Support for decode data to struct\n- Support data override merge\n- Support parse ENV variable\n- Support comments start with  `;` `#`, multi line comments `/* .. */`\n- Support multi line value with `\"\"\"` or `'''`\n- Complete unit test(coverage \u003e 90%)\n- Support variable reference, default compatible with Python's configParser format `%(VAR)s`\n\n### [Parser](./parser)\n\nPackage `parser` is a Parser for parse INI format content to golang data\n\n### [Dotenv](./dotenv)\n\nPackage `dotenv` that supports importing ENV data from files (eg `.env`)\n\n## More formats\n\nIf you want more support for file content formats, recommended use `gookit/config`\n\n- [gookit/config](https://github.com/gookit/config) - Support multi formats: `JSON`(default), `INI`, `YAML`, `TOML`, `HCL`\n\n## GoDoc\n\n- [godoc](https://pkg.go.dev/github.com/gookit/ini)\n\n## Install\n\n```bash\ngo get github.com/gookit/ini/v2\n```\n\n## Usage\n\n- example data(`testdata/test.ini`):\n\n```ini\n# comments\nname = inhere\nage = 50\ndebug = true\nhasQuota1 = 'this is val'\nhasQuota2 = \"this is val1\"\ncan2arr = val0,val1,val2\nshell = ${SHELL}\nnoEnv = ${NotExist|defValue}\nnkey = val in default section\n\n; comments\n[sec1]\nkey = val0\nsome = value\nstuff = things\nvarRef = %(nkey)s\n```\n\n### Load data\n\n```go\npackage main\n\nimport (\n\t\"github.com/gookit/ini/v2\"\n)\n\n// go run ./examples/demo.go\nfunc main() {\n\t// config, err := ini.LoadFiles(\"testdata/tesdt.ini\")\n\t// LoadExists will ignore not exists file\n\terr := ini.LoadExists(\"testdata/test.ini\", \"not-exist.ini\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// load more, will override prev data by key\n\terr = ini.LoadStrings(`\nage = 100\n[sec1]\nnewK = newVal\nsome = change val\n`)\n\t// fmt.Printf(\"%v\\n\", config.Data())\n}\n```\n\n### Read data\n\n- Get integer\n\n```go\nage := ini.Int(\"age\")\nfmt.Print(age) // 100\n```\n\n- Get bool\n\n```go\nval := ini.Bool(\"debug\")\nfmt.Print(val) // true\n```\n\n- Get string\n\n```go\nname := ini.String(\"name\")\nfmt.Print(name) // inhere\n```\n\n- Get section data(string map)\n\n```go\nval := ini.StringMap(\"sec1\")\nfmt.Println(val) \n// map[string]string{\"key\":\"val0\", \"some\":\"change val\", \"stuff\":\"things\", \"newK\":\"newVal\"}\n```\n\n- Value is ENV var\n\n```go\nvalue := ini.String(\"shell\")\nfmt.Printf(\"%q\", value)  // \"/bin/zsh\"\n```\n\n- **Get value by key path**\n\n```go\nvalue := ini.String(\"sec1.key\")\nfmt.Print(value) // val0\n```\n\n- Use var refer\n\n```go\nvalue := ini.String(\"sec1.varRef\")\nfmt.Printf(\"%q\", value) // \"val in default section\"\n```\n\n- Set new value\n\n```go\n// set value\nini.Set(\"name\", \"new name\")\nname = ini.String(\"name\")\nfmt.Printf(\"%q\", name) // \"new name\"\n```\n\n## Mapping data to struct\n\n```go\ntype User struct {\n\tName string\n\tAge int\n}\n\nuser := \u0026User{}\nini.MapStruct(ini.DefSection(), user)\n\ndump.P(user)\n```\n\nSpecial, mapping all data:\n\n```go\nini.MapStruct(\"\", ptr)\n```\n\n## Variable reference resolution\n\n```ini\n[portal] \nurl = http://%(host)s:%(port)s/api\nhost = localhost \nport = 8080\n```\n\nIf variable resolution is enabled，will parse `%(host)s` and replace it：\n\n```go\ncfg := ini.New()\n// enable ParseVar\ncfg.WithOptions(ini.ParseVar)\n\nfmt.Print(cfg.MustString(\"portal.url\"))\n// OUT: \n// http://localhost:8080/api \n```\n\n## Available options\n\n```go\ntype Options struct {\n\t// set to read-only mode. default False\n\tReadonly bool\n\t// parse ENV var name. default True\n\tParseEnv bool\n\t// parse variable reference \"%(varName)s\". default False\n\tParseVar bool\n\n\t// var left open char. default \"%(\"\n\tVarOpen string\n\t// var right close char. default \")s\"\n\tVarClose string\n\n\t// ignore key name case. default False\n\tIgnoreCase bool\n\t// default section name. default \"__default\"\n\tDefSection string\n\t// sep char for split key path. default \".\", use like \"section.subKey\"\n\tSectionSep string\n}\n```\n\nSetting options for default instance:\n\n```go\nini.WithOptions(ini.ParseEnv,ini.ParseVar)\n```\n\nSetting options with new instance:\n\n```go\ncfg := ini.New()\ncfg.WithOptions(ini.ParseEnv, ini.ParseVar, func (opts *Options) {\n\topts.SectionSep = \":\"\n\topts.DefSection = \"default\"\n})\n```\n\n## Dotenv\n\nPackage `dotenv` that supports importing data from files (eg `.env`) to ENV\n\n### Usage\n\n```go\nerr := dotenv.Load(\"./\", \".env\")\n// err := dotenv.LoadExists(\"./\", \".env\")\n\nval := dotenv.Get(\"ENV_KEY\")\n// Or use \n// val := os.Getenv(\"ENV_KEY\")\n\n// get int value\nintVal := dotenv.Int(\"LOG_LEVEL\")\n\n// with default value\nval := dotenv.Get(\"ENV_KEY\", \"default value\")\n```\n\n## Tests\n\n- go tests with cover\n\n```bash\ngo test ./... -cover\n```\n\n- run lint by GoLint\n\n```bash\ngolint ./...\n```\n\n## Gookit packages\n\n- [gookit/ini](https://github.com/gookit/ini) Go config management, use INI files\n- [gookit/rux](https://github.com/gookit/rux) Simple and fast request router for golang HTTP\n- [gookit/gcli](https://github.com/gookit/gcli) Build CLI application, tool library, running CLI commands\n- [gookit/slog](https://github.com/gookit/slog) Lightweight, easy to extend, configurable logging library written in Go\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/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/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## Related\n\n- [go-ini/ini](https://github.com/go-ini/ini) ini parser and config manage\n- [dombenson/go-ini](https://github.com/dombenson/go-ini) ini parser and config manage\n\n## License\n\n**MIT**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgookit%2Fini","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgookit%2Fini","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgookit%2Fini/lists"}