# ConfigReplaceGoTool **Repository Path**: ouhaoqiang/ConfigReplaceGoTool ## Basic Information - **Project Name**: ConfigReplaceGoTool - **Description**: 配置替换工具。 - **Primary Language**: Go - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-09-09 - **Last Updated**: 2022-09-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # ConfigReplaceGoTool #### 介绍 配置替换工具。 #### 软件架构 Go语言编译的配置替换工具。 #### 安装教程 ##### 一、源码安装 ```shell # clone仓库 git clone https://gitee.com/ouhaoqiang/ConfigReplaceGoTool.git # 初始化go环境 cd ConfigReplaceGoTool go mod init "gitee.com/ouhaoqiang/ConfigReplaceGoTool" go mod tidy # 编译 go build ConfigReplaceGoTool.go # 使用案例 chmod +x ConfigReplaceGoTool ./ConfigReplaceGoTool -c demo/globalconfig-template.ini -t demo/serverconfig-template.ini -debug ``` #### 使用说明 1. 常用方式 直接替换模板文件 ```shell ./ConfigReplaceGoTool -c demo/globalconfig-template.ini -t demo/serverconfig-template.ini ``` 2. 调试模式 ```shell ./ConfigReplaceGoTool -c demo/globalconfig-template.ini -t demo/serverconfig-template.ini -debug ``` 3. 输出到其他路径 ```shell ./ConfigReplaceGoTool -c demo/globalconfig-template.ini -t demo/serverconfig-template.ini -o test.ini ``` 4. 帮助 ```shell ./ConfigReplaceGoTool -h ``` #### 参数说明 ##### -c, -config(必选参数) - 配置文件路径(全局配置文件) ##### -t, -template(必选参数) - 被替换的模板文件路径 ##### -o, -out(可选参数) - 输出到另外的文件路径,不替换原来的模板文件。 - 如果不选,默认替换原来的模板文件。 ##### -debug(可选参数) - 调试模式,只将替换内容输出到终端,不做实际操作。 #### 模板文件格式说明 ##### 模板文件 - #var.{被替换的变量名称}=${配置文件里面的变量名称} - `#var.` `=` `${}` 是关键字 - `=` 后面可以有其他固定参数 `#var.url=http://${url}:8000` - 如果配置文件是ini格式可以使用 `#var.host=${redis.redis_host}` - 目前模板只适配 `key=value` - 如果指定了模板,但是配置文件里面没有这个key,那么就不会被替换。例如url替换后还是为空。 [serverconfig-template.ini](./demo/serverconfig-template.ini) ```ini #var.url=http://${url}:8000 url= # 读取默认参数示例。 [user] #var.name=${name} name= #var.age=${age} age=100 [mysql] #var.host=http://${mysql_host} host="127.0.0.2" #var.prot=${mysql_prot} prot=3306 #var.user=${mysql_user} user= #var.password=${mysql_password} password=3344 # 读取分区示例。 [redis] #var.host=${redis.redis_host} host= #var.prot=${redis.redis_prot} prot=321 #var.password=${redis.redis_password} password= ``` ##### 配置文件 [globalconfig-template.ini](./demo/globalconfig-template.ini) - 配置文件支持`key=value`的格式。 - 也支持ini格式,既`redis.host`(分区.变量) ```ini # user info name=ouhaoqiang age=18 # mysql info mysql_host="127.0.0.1" mysql_prot=3306 mysql_user=root mysql_password=123 # redis info [redis] redis_host="127.0.0.1" redis_prot=6379 redis_password=123 ``` #### 参与贡献 1. Fork 本仓库 2. 新建 Feat_xxx 分支 3. 提交代码 4. 新建 Pull Request #### 特技 1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md 2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) 3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) 6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)