{"id":26568801,"url":"https://github.com/hyahm/goconfig","last_synced_at":"2025-09-21T12:21:02.803Z","repository":{"id":57484042,"uuid":"195922099","full_name":"hyahm/goconfig","owner":"hyahm","description":"golang  read config like ini,  support ini, json, yaml using ","archived":false,"fork":false,"pushed_at":"2022-04-16T01:34:34.000Z","size":164,"stargazers_count":8,"open_issues_count":0,"forks_count":2,"subscribers_count":0,"default_branch":"master","last_synced_at":"2024-06-19T10:15:35.764Z","etag":null,"topics":["config","go","ini","json","yaml"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hyahm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-07-09T03:00:00.000Z","updated_at":"2023-10-23T09:18:55.000Z","dependencies_parsed_at":"2022-08-26T14:20:41.345Z","dependency_job_id":null,"html_url":"https://github.com/hyahm/goconfig","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/hyahm%2Fgoconfig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyahm%2Fgoconfig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyahm%2Fgoconfig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyahm%2Fgoconfig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hyahm","download_url":"https://codeload.github.com/hyahm/goconfig/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245013989,"owners_count":20547181,"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","go","ini","json","yaml"],"created_at":"2025-03-22T20:17:34.281Z","updated_at":"2025-09-21T12:20:57.739Z","avatar_url":"https://github.com/hyahm.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# goconfig\nread go config from key value ini file\n\n### 安装\n```\ngo get github.com/hyahm/goconfig\n```\n### 注意\n- 支持读取任何单行配置文件\n- 自定义符号\n- 支持写入配置文件\n- 支持变量\n\n# 使用\n\n### 自定义符号, 加载配置文件之前定义, 只对ini文件的kv值有效\n```ini\nSEP         = \"=\"  // key 和 value 分隔符\nNOTE        = \"#;\" // #开头的为注释\nMODEL_START = \"[\"  // 模块开头符号\nMODEL_END   = \"]\"  // 模块结尾符号\nWELL        = \"#\"  // 写入的注释， \nDeep   // 默认值有效个数， 默认为3\n```\n\n\n### 读取配置\n\u003e test.ini\n```vim\n$var=\"I am a variable value\"\n[mysql]\nhost=192.168.80.2\nport=name${var}\nname=name${var}\n```\n\n\u003e 第一个参数后面表示默认值，默认支持长度为3， 如果不存在key， 或者读取的值不符合读取类型的默认值\n```\n\ngoconfig.InitConf(\"test.ini\")\ngoconfig.ReadString(\"mysql.host\", \"127.0.0.1\") // return 192.168.80.2\ngoconfig.ReadInt(\"mysql.port\", 3306)    // return 3306\ngoconfig.ReadString(\"mysql.db\", \"name\")    // return name\ngoconfig.ReadString(\"mysql.deep\", \"one\", \"two\", \"three\")    // return one\ngoconfig.ReadString(\"mysql.deep\", \"\", \"two\", \"three\")    // return two\ngoconfig.ReadString(\"mysql.deep\", \"\", \"\", \"three\")    // return three\ngoconfig.ReadString(\"mysql.name\", \"\") // return nameI am a variable value\ngoconfig.ReadString(\"var\", \"\") // return I am a variable value\n```\n\n\n\u003e 从[]byte 读取\n```vim\n```go\nx := `[mysql]\nhost=192.168.80.2\nport=name\n`\n当然也可以是传过来的数据进行解析\ngoconfig.InitFromBytes([]byte(x))\ngoconfig.ReadString(\"mysql.host\", \"127.0.0.1\") // return 192.168.80.2\ngoconfig.ReadInt(\"mysql.port\", 3306)    // return 3306\ngoconfig.ReadString(\"mysql.db\", \"name\")    // return name\n```\n### 写入配置文件\n```\ngoconfig.InitWriteConf(\"write.conf\")  // 与InitConf的区别是， 这个会清空里面原有数据\ngoconfig.InitConf(\"test.conf\")  // 原有配置文件添加\ngoconfig.WriteString(\"mysql.host\", \"127.0.0.1\",\"mysql数据库host\") \ngoconfig.WriteInt(\"mysql.port\", 3306)   \ngoconfig.WriteString(\"mysql.db\", \"name\")   \ngoconfig.FlushWrite()  // 缓存一次写入文件， 写入别忘了这行\n```\n\u003e test.conf\n```\n[mysql]\n# mysql数据库host\nhost = 127.0.0.1\nport = 3306\ndb = name\n```\n\n### 配置文件软加载方法\nerr = Reload(),  仅限InitConf(file)  从文件读取的软加载， 自己写接口调用此方法， 配置文件会刷新， 如果配置文件有错则不会更新\n\n\n# 辅助方法， 方便调试\nPrintLines() // 打印读取的配置文件  \nPrintKeyValue()  // 打印kv数据  \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyahm%2Fgoconfig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhyahm%2Fgoconfig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyahm%2Fgoconfig/lists"}