{"id":47796398,"url":"https://github.com/iotames/easyconf","last_synced_at":"2026-04-03T16:25:19.522Z","repository":{"id":237538733,"uuid":"794676356","full_name":"iotames/easyconf","owner":"iotames","description":"用于Go项目的配置项管理工具，方便生成和读取 env 配置文件的环境变量。","archived":false,"fork":false,"pushed_at":"2026-02-07T03:36:44.000Z","size":48,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-02-07T13:59:29.339Z","etag":null,"topics":["config","configuration","go","golang","setting"],"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/iotames.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-05-01T18:04:52.000Z","updated_at":"2026-02-07T03:36:10.000Z","dependencies_parsed_at":"2024-06-19T11:22:09.797Z","dependency_job_id":"2e17c00c-0365-44b9-8f37-ccd5be9c5aad","html_url":"https://github.com/iotames/easyconf","commit_stats":null,"previous_names":["iotames/easyconf"],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/iotames/easyconf","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iotames%2Feasyconf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iotames%2Feasyconf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iotames%2Feasyconf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iotames%2Feasyconf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iotames","download_url":"https://codeload.github.com/iotames/easyconf/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iotames%2Feasyconf/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31362723,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-03T15:19:21.178Z","status":"ssl_error","status_checked_at":"2026-04-03T15:19:20.670Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6: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":["config","configuration","go","golang","setting"],"created_at":"2026-04-03T16:25:18.258Z","updated_at":"2026-04-03T16:25:19.351Z","avatar_url":"https://github.com/iotames.png","language":"Go","readme":"## 简介\n\n简单的Go应用程序配置工具，用于生成和读取 `env` 配置文件的环境变量。\n\n可以很方便地定义 `配置名`，`默认值`，`注释标题`，`注释说明`（多行）。\n\n通过简单的方法读取和修改配置值。\n\n优先级：`命令行同名参数值` \u003e `环境变量值` \u003e `配置文件配置值`\n\n\n## 新建配置\n\n\n导入 `easyconf` 工具包:\n\n```\nimport (\n\t\"github.com/iotames/easyconf\"\n)\n```\n\n可初始化1个或多个配置文件，优先级从左到右。默认: `.env`, `default.env`\n\n```\n// 生成 .env, default.env 两份配置文件。\ncf := easyconf.NewConf()\n\n// 生成一份 myconf.env 自定义配置文件。\ncf = easyconf.NewConf(\"myconf.env\")\n\n// 生成多份配置文件\ncf = easyconf.NewConf(\".env\", \"common.env\", \"default.env\")\n```\n\n使用 `Parse(fale)` 方法读取文件中的配置值。若文件不存在，则创建。\n\n```\nvar DbHost string\nvar DbPort int\ncf := easyconf.NewConf()\ncf.StringVar(\u0026DbHost, \"DB_HOST\", \"127.0.0.1\", \"数据库主机地址\")\ncf.IntVar(\u0026DbPort, \"DB_PORT\", 3306, \"数据库地址端口号\")\ncf.Parse(false) // 默认创建 .env, default.env 两份文件。\n```\n\n## 更新配置\n\n使用 `UpdateFile()` 方法更新配置。需要指定配置文件路径，留空则默认更新第一个。\n\n```\ncf := easyconf.NewConf(\".env\")\nvar DbHost string\ncf.StringVar(\u0026DbHost, \"DB_HOST\", \"127.0.0.1\", \"数据库主机地址\")\ncf.Parse(false)\n\nDbHost = \"192.168.1.6\"\n\n// 可指定一个更新的配置文件。留空则默认更新第一个。\nerr := cf.UpdateFile(\"\")\nif err != nil {\n\tpanic(err)\n}\n```\n\n## 完整示例\n\n```\npackage main\n\nimport (\n\t\"flag\"\n\t\"fmt\"\n\t\"os\"\n\n\t\"github.com/iotames/easyconf\"\n)\n\n// 可修改 envfile 文件中配置项的值，验证值是否更新\nconst DEFAULT_ENV_FILE = \".env\"\n\nconst DEFAULT_DB_HOST = \"127.0.0.1\"\nconst DEFAULT_DB_PORT = 3306\n\nvar envfile string\n\nvar cf *easyconf.Conf\n\nvar DbHost string\nvar DbPort int\nvar DbEnable bool\nvar AllowIPs []string\nvar AgeRange []int\n\nfunc main() {\n\tfmt.Printf(\"-------可修改envfile(%s)文件中配置项的默认值，验证修改值是否更新-----\\n\", getEnvFile())\n\tfmt.Printf(\"-----DbHost(%s)--DbPort(%d)--Dbnable(%t)--\\n\", DbHost, DbPort, DbEnable)\n\tfmt.Printf(\"-----AllowIPs(%+v)--AgeRange(%v)--\\n\", AllowIPs, AgeRange)\n\tif DbHost == DEFAULT_DB_HOST {\n\t\tDbHost = \"192.168.1.19\"\n\t\tDbPort = 3308\n\t\terr := cf.UpdateFile(getEnvFile())\n\t\tif err != nil {\n\t\t\tpanic(err)\n\t\t}\n\t\tfmt.Printf(\"SUCCESS: Update Env File:%s\\n\", getEnvFile())\n\t}\n}\n\nfunc init() {\n\tflag.StringVar(\u0026envfile, \"envfile\", \"\", \"配置文件路径\")\n\tflag.Parse()\n\tcf = easyconf.NewConf(getEnvFile())\n\tcf.StringVar(\u0026DbHost, \"DB_HOST\", DEFAULT_DB_HOST, \"数据库主机地址\")\n\tcf.IntVar(\u0026DbPort, \"DB_PORT\", DEFAULT_DB_PORT, \"数据库地址端口号\")\n\tcf.BoolVar(\u0026DbEnable, \"DB_ENABLE\", false, \"是否启用数据库\")\n\tcf.StringListVar(\u0026AllowIPs, \"ALLOW_IP_LIST\", []string{\"192.168.1.6\", \"192.168.2.8\"}, \"允许访问的IP列表，每个IP用逗号(,)隔开。\")\n\tcf.IntListVar(\u0026AgeRange, \"AGE_RANGE\", []int{3, 6}, \"年龄范围\", \"填写2个正整数,中间用逗号,隔开\")\n\tcf.Parse(false)\n}\n\nfunc getEnvFile() string {\n\tefile := envfile\n\tif efile == \"\" {\n\t\tefile = os.Getenv(\"ENV_FILE\")\n\t}\n\tif efile == \"\" {\n\t\tefile = DEFAULT_ENV_FILE\n\t}\n\treturn efile\n}\n\n\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiotames%2Feasyconf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiotames%2Feasyconf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiotames%2Feasyconf/lists"}