Skip to content

Commit

Permalink
feat: add DINGTALK_ENV_PREFIX
Browse files Browse the repository at this point in the history
  • Loading branch information
CatchZeng committed Apr 20, 2022
1 parent 97ab8ac commit 6e99935
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"cSpell.words": ["btns", "gomock", "mitchellh", "OAPI", "Unpatch"]
"cSpell.words": ["btns", "dingtalk", "gomock", "mitchellh", "OAPI", "Unpatch"]
}
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CHANGELOG

## v1.5.0

### Added

- Support the environment variable prefix

## v1.4.0

### Added
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
21 changes: 15 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

## 使用方法
Expand All @@ -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
Expand All @@ -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'
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions READMEEN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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'
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/dingtalk/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion configs/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 != "" {
Expand Down

0 comments on commit 6e99935

Please sign in to comment.