Skip to content

Commit 6e99935

Browse files
committed
feat: add DINGTALK_ENV_PREFIX
1 parent 97ab8ac commit 6e99935

File tree

7 files changed

+33
-15
lines changed

7 files changed

+33
-15
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"cSpell.words": ["btns", "gomock", "mitchellh", "OAPI", "Unpatch"]
2+
"cSpell.words": ["btns", "dingtalk", "gomock", "mitchellh", "OAPI", "Unpatch"]
33
}

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# CHANGELOG
22

3+
## v1.5.0
4+
5+
### Added
6+
7+
- Support the environment variable prefix
8+
39
## v1.4.0
410

511
### Added

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ SHELL := /bin/bash
22
BASEDIR = $(shell pwd)
33

44
APP_NAME=dingtalk
5-
APP_VERSION=1.4.0
5+
APP_VERSION=1.5.0
66
IMAGE_NAME="catchzeng/${APP_NAME}:${APP_VERSION}"
77
IMAGE_LATEST="catchzeng/${APP_NAME}:latest"
88

README.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ docker pull catchzeng/dingtalk
7272

7373
```sh
7474
# Go 1.16+
75-
go install github.com/CatchZeng/dingtalk@v1.4.0
75+
go install github.com/CatchZeng/dingtalk@v1.5.0
7676

7777
# Go version < 1.16
78-
go get -u github.com/CatchZeng/dingtalk@v1.4.0
78+
go get -u github.com/CatchZeng/dingtalk@v1.5.0
7979
```
8080

8181
## 使用方法
@@ -92,9 +92,18 @@ secret: "SECb90923e19e58b466481e9e7b7a5bxxxxxx4531axxxxxxad3967fb29f0eae5c68"
9292
### 环境变量
9393
9494
```sh
95-
$ export ACCESS_TOKEN=1c53e149ba5de6597cxxxxxx0e901fdxxxxxx80b8ac141e4a75afdc44c85ca4f
96-
$ export SECRET=SECb90923e19e58b466481e9e7b7a5bxxxxxx4531axxxxxxad3967fb29f0eae5c68
97-
$ dingtalk link -i "标题" -e "信息" -u "https://catchzeng.com/" -p "https://catchzeng.com/img/avatar-hux.jpg" -a
95+
$ export ACCESS_TOKEN="1c53e149ba5de6597cxxxxxx0e901fdxxxxxx80b8ac141e4a75afdc44c85ca4f"
96+
$ export SECRET="SECb90923e19e58b466481e9e7b7a5bxxxxxx4531axxxxxxad3967fb29f0eae5c68"
97+
$ dingtalk link -i "标题" -e "信息" -u "https://makeoptim.com/" -p "https://makeoptim.com/assets/img/logo.png" -a
98+
```
99+
100+
你也可以为环境变量设置一个**前缀**
101+
102+
```sh
103+
$ export DINGTALK_ENV_PREFIX="DINGTALK_"
104+
$ export DINGTALK_ACCESS_TOKEN="1c53e149ba5de6597cxxxxxx0e901fdxxxxxx80b8ac141e4a75afdc44c85ca4f"
105+
$ export DINGTALK_SECRET="SECb90923e19e58b466481e9e7b7a5bxxxxxx4531axxxxxxad3967fb29f0eae5c68"
106+
$ dingtalk link -i "标题" -e "信息" -u "https://makeoptim.com/" -p "https://makeoptim.com/assets/img/logo.png" -a
98107
```
99108

100109
### Docker
@@ -119,7 +128,7 @@ pipeline {
119128
stages {
120129
stage('notify') {
121130
steps {
122-
sh 'dingtalk link -t ${DING_TOKEN} -s ${DING_SECRET} -i "标题" -e "信息" -u "https://catchzeng.com/" -p "https://catchzeng.com/img/avatar-hux.jpg" -a'
131+
sh 'dingtalk link -t ${DING_TOKEN} -s ${DING_SECRET} -i "标题" -e "信息" -u "https://makeoptim.com/" -p "https://makeoptim.com/assets/img/logo.png" -a'
123132
}
124133
}
125134
}

READMEEN.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ Go to [releases](https://github.com/CatchZeng/dingtalk/releases/) to download th
7070

7171
```sh
7272
# Go 1.16+
73-
go install github.com/CatchZeng/dingtalk@v1.4.0
73+
go install github.com/CatchZeng/dingtalk@v1.5.0
7474

7575
# Go version < 1.16
76-
go get -u github.com/CatchZeng/dingtalk@v1.4.0
76+
go get -u github.com/CatchZeng/dingtalk@v1.5.0
7777
```
7878

7979
## Usage
@@ -92,7 +92,7 @@ secret: "SECb90923e19e58b466481e9e7b7a5bxxxxxx4531axxxxxxad3967fb29f0eae5c68"
9292
```sh
9393
$ export ACCESS_TOKEN=1c53e149ba5de6597cxxxxxx0e901fdxxxxxx80b8ac141e4a75afdc44c85ca4f
9494
$ export SECRET=SECb90923e19e58b466481e9e7b7a5bxxxxxx4531axxxxxxad3967fb29f0eae5c68
95-
$ dingtalk link -i "标题" -e "信息" -u "https://catchzeng.com/" -p "https://catchzeng.com/img/avatar-hux.jpg" -a
95+
$ dingtalk link -i "标题" -e "信息" -u "https://makeoptim.com/" -p "https://makeoptim.com/assets/img/logo.png" -a
9696
```
9797

9898
### Docker
@@ -117,7 +117,7 @@ pipeline {
117117
stages {
118118
stage('notify') {
119119
steps {
120-
sh 'dingtalk link -t ${DING_TOKEN} -s ${DING_SECRET} -i "标题" -e "信息" -u "https://catchzeng.com/" -p "https://catchzeng.com/img/avatar-hux.jpg" -a'
120+
sh 'dingtalk link -t ${DING_TOKEN} -s ${DING_SECRET} -i "标题" -e "信息" -u "https://makeoptim.com/" -p "https://makeoptim.com/assets/img/logo.png" -a'
121121
}
122122
}
123123
}

cmd/dingtalk/version.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
)
99

1010
const (
11-
version = "1.4.0"
12-
buildTime = "2022/04/18"
11+
version = "1.5.0"
12+
buildTime = "2022/04/20"
1313
)
1414

1515
// versionCmd represents the version command

configs/configs.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ func InitConfig() {
2323
viper.AddConfigPath(configPath)
2424
viper.SetConfigName("config")
2525

26+
envPrefix := os.Getenv("DINGTALK_ENV_PREFIX")
27+
viper.SetEnvPrefix(envPrefix)
2628
viper.AutomaticEnv() // read in environment variables that match
2729

2830
// If a configs file is found, read it in.
@@ -35,7 +37,8 @@ func InitConfig() {
3537
// GetConfig get configs with key
3638
func GetConfig(key string) (string, error) {
3739
// Check the environment variable
38-
envKey := strings.ToUpper(key)
40+
envPrefix := os.Getenv("DINGTALK_ENV_PREFIX")
41+
envKey := envPrefix + strings.ToUpper(key)
3942
result := os.Getenv(envKey)
4043

4144
if result != "" {

0 commit comments

Comments
 (0)