From 6e999355f0725a6d853201672bb84481b786c6bf Mon Sep 17 00:00:00 2001 From: CatchZeng <891793848@qq.com> Date: Wed, 20 Apr 2022 18:24:41 +0800 Subject: [PATCH] feat: add DINGTALK_ENV_PREFIX --- .vscode/settings.json | 2 +- CHANGELOG.md | 6 ++++++ Makefile | 2 +- README.md | 21 +++++++++++++++------ READMEEN.md | 8 ++++---- cmd/dingtalk/version.go | 4 ++-- configs/configs.go | 5 ++++- 7 files changed, 33 insertions(+), 15 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 245a7c7..565b6e4 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,3 @@ { - "cSpell.words": ["btns", "gomock", "mitchellh", "OAPI", "Unpatch"] + "cSpell.words": ["btns", "dingtalk", "gomock", "mitchellh", "OAPI", "Unpatch"] } diff --git a/CHANGELOG.md b/CHANGELOG.md index 1502d07..1b89cb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # CHANGELOG +## v1.5.0 + +### Added + +- Support the environment variable prefix + ## v1.4.0 ### Added diff --git a/Makefile b/Makefile index fe27f79..ef2f488 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ SHELL := /bin/bash BASEDIR = $(shell pwd) APP_NAME=dingtalk -APP_VERSION=1.4.0 +APP_VERSION=1.5.0 IMAGE_NAME="catchzeng/${APP_NAME}:${APP_VERSION}" IMAGE_LATEST="catchzeng/${APP_NAME}:latest" diff --git a/README.md b/README.md index eccdb16..af7ce9d 100644 --- a/README.md +++ b/README.md @@ -72,10 +72,10 @@ docker pull catchzeng/dingtalk ```sh # Go 1.16+ -go install github.com/CatchZeng/dingtalk@v1.4.0 +go install github.com/CatchZeng/dingtalk@v1.5.0 # Go version < 1.16 -go get -u github.com/CatchZeng/dingtalk@v1.4.0 +go get -u github.com/CatchZeng/dingtalk@v1.5.0 ``` ## 使用方法 @@ -92,9 +92,18 @@ secret: "SECb90923e19e58b466481e9e7b7a5bxxxxxx4531axxxxxxad3967fb29f0eae5c68" ### 环境变量 ```sh -$ export ACCESS_TOKEN=1c53e149ba5de6597cxxxxxx0e901fdxxxxxx80b8ac141e4a75afdc44c85ca4f -$ export SECRET=SECb90923e19e58b466481e9e7b7a5bxxxxxx4531axxxxxxad3967fb29f0eae5c68 -$ dingtalk link -i "标题" -e "信息" -u "https://catchzeng.com/" -p "https://catchzeng.com/img/avatar-hux.jpg" -a +$ export ACCESS_TOKEN="1c53e149ba5de6597cxxxxxx0e901fdxxxxxx80b8ac141e4a75afdc44c85ca4f" +$ export SECRET="SECb90923e19e58b466481e9e7b7a5bxxxxxx4531axxxxxxad3967fb29f0eae5c68" +$ dingtalk link -i "标题" -e "信息" -u "https://makeoptim.com/" -p "https://makeoptim.com/assets/img/logo.png" -a +``` + +你也可以为环境变量设置一个**前缀** + +```sh +$ export DINGTALK_ENV_PREFIX="DINGTALK_" +$ export DINGTALK_ACCESS_TOKEN="1c53e149ba5de6597cxxxxxx0e901fdxxxxxx80b8ac141e4a75afdc44c85ca4f" +$ export DINGTALK_SECRET="SECb90923e19e58b466481e9e7b7a5bxxxxxx4531axxxxxxad3967fb29f0eae5c68" +$ dingtalk link -i "标题" -e "信息" -u "https://makeoptim.com/" -p "https://makeoptim.com/assets/img/logo.png" -a ``` ### Docker @@ -119,7 +128,7 @@ pipeline { stages { stage('notify') { steps { - sh 'dingtalk link -t ${DING_TOKEN} -s ${DING_SECRET} -i "标题" -e "信息" -u "https://catchzeng.com/" -p "https://catchzeng.com/img/avatar-hux.jpg" -a' + sh 'dingtalk link -t ${DING_TOKEN} -s ${DING_SECRET} -i "标题" -e "信息" -u "https://makeoptim.com/" -p "https://makeoptim.com/assets/img/logo.png" -a' } } } diff --git a/READMEEN.md b/READMEEN.md index b5083d3..b9dc146 100644 --- a/READMEEN.md +++ b/READMEEN.md @@ -70,10 +70,10 @@ Go to [releases](https://github.com/CatchZeng/dingtalk/releases/) to download th ```sh # Go 1.16+ -go install github.com/CatchZeng/dingtalk@v1.4.0 +go install github.com/CatchZeng/dingtalk@v1.5.0 # Go version < 1.16 -go get -u github.com/CatchZeng/dingtalk@v1.4.0 +go get -u github.com/CatchZeng/dingtalk@v1.5.0 ``` ## Usage @@ -92,7 +92,7 @@ secret: "SECb90923e19e58b466481e9e7b7a5bxxxxxx4531axxxxxxad3967fb29f0eae5c68" ```sh $ export ACCESS_TOKEN=1c53e149ba5de6597cxxxxxx0e901fdxxxxxx80b8ac141e4a75afdc44c85ca4f $ export SECRET=SECb90923e19e58b466481e9e7b7a5bxxxxxx4531axxxxxxad3967fb29f0eae5c68 -$ dingtalk link -i "标题" -e "信息" -u "https://catchzeng.com/" -p "https://catchzeng.com/img/avatar-hux.jpg" -a +$ dingtalk link -i "标题" -e "信息" -u "https://makeoptim.com/" -p "https://makeoptim.com/assets/img/logo.png" -a ``` ### Docker @@ -117,7 +117,7 @@ pipeline { stages { stage('notify') { steps { - sh 'dingtalk link -t ${DING_TOKEN} -s ${DING_SECRET} -i "标题" -e "信息" -u "https://catchzeng.com/" -p "https://catchzeng.com/img/avatar-hux.jpg" -a' + sh 'dingtalk link -t ${DING_TOKEN} -s ${DING_SECRET} -i "标题" -e "信息" -u "https://makeoptim.com/" -p "https://makeoptim.com/assets/img/logo.png" -a' } } } diff --git a/cmd/dingtalk/version.go b/cmd/dingtalk/version.go index 0dc6f80..55fbfd3 100644 --- a/cmd/dingtalk/version.go +++ b/cmd/dingtalk/version.go @@ -8,8 +8,8 @@ import ( ) const ( - version = "1.4.0" - buildTime = "2022/04/18" + version = "1.5.0" + buildTime = "2022/04/20" ) // versionCmd represents the version command diff --git a/configs/configs.go b/configs/configs.go index c1fa88a..bf54e18 100644 --- a/configs/configs.go +++ b/configs/configs.go @@ -23,6 +23,8 @@ func InitConfig() { viper.AddConfigPath(configPath) viper.SetConfigName("config") + envPrefix := os.Getenv("DINGTALK_ENV_PREFIX") + viper.SetEnvPrefix(envPrefix) viper.AutomaticEnv() // read in environment variables that match // If a configs file is found, read it in. @@ -35,7 +37,8 @@ func InitConfig() { // GetConfig get configs with key func GetConfig(key string) (string, error) { // Check the environment variable - envKey := strings.ToUpper(key) + envPrefix := os.Getenv("DINGTALK_ENV_PREFIX") + envKey := envPrefix + strings.ToUpper(key) result := os.Getenv(envKey) if result != "" {