Skip to content

Commit

Permalink
feat: add env config
Browse files Browse the repository at this point in the history
  • Loading branch information
CatchZeng committed Apr 18, 2022
1 parent 21fbf61 commit 9782c51
Show file tree
Hide file tree
Showing 9 changed files with 386 additions and 188 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
dingtalk-darwin-amd64.zip
dingtalk-darwin-arm64.zip
dingtalk-linux-amd64.zip
dingtalk-windows-386.zip
dingtalk-windows-amd64.zip
Expand Down
11 changes: 8 additions & 3 deletions 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.3.3
APP_VERSION=1.4.0
IMAGE_NAME="catchzeng/${APP_NAME}:${APP_VERSION}"
IMAGE_LATEST="catchzeng/${APP_NAME}:latest"

Expand All @@ -27,10 +27,14 @@ mock:
build:
rm -f dingtalk
go build -o dingtalk main.go
build-mac:
build-darwin-amd64:
rm -f dingtalk dingtalk-darwin-amd64.zip
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o dingtalk main.go
zip dingtalk-darwin-amd64.zip dingtalk
build-darwin-arm64:
rm -f dingtalk dingtalk-darwin-arm64.zip
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o dingtalk main.go
zip dingtalk-darwin-arm64.zip dingtalk
build-linux:
rm -f dingtalk dingtalk-linux-amd64.zip
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o dingtalk main.go
Expand All @@ -44,7 +48,8 @@ build-win32:
CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -o dingtalk.exe main.go
zip dingtalk-windows-386.zip dingtalk.exe
build-release:
make build-mac
make build-darwin-amd64
make build-darwin-arm64
make build-linux
make build-win
make build-win32
Expand Down
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

- [x] 支持[配置文件](https://github.com/CatchZeng/dingtalk#%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6)

- [x] 支持[环境变量](https://github.com/CatchZeng/dingtalk#%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F)

- [x] 支持加签

<img src="https://dingtalkdoc.oss-cn-beijing.aliyuncs.com/images/0.0.210/1572261283991-f8e35f4d-6997-4a02-9704-843ee8f97464.png" width = 50% />
Expand Down Expand Up @@ -70,10 +72,10 @@ docker pull catchzeng/dingtalk

```sh
# Go 1.16+
go install github.com/CatchZeng/dingtalk@v1.3.3
go install github.com/CatchZeng/dingtalk@v1.4.0

# Go version < 1.16
go get -u github.com/CatchZeng/dingtalk@v1.3.3
go get -u github.com/CatchZeng/dingtalk@v1.4.0
```

## 使用方法
Expand All @@ -87,6 +89,14 @@ access_token: "1c53e149ba5de6597cxxxxxx0e901fdxxxxxx80b8ac141e4a75afdc44c85ca4f"
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
```

### Docker

```shell
Expand Down
14 changes: 12 additions & 2 deletions READMEEN.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

- [x] Support [config.yaml](https://github.com/CatchZeng/dingtalk/blob/master/READMEEN.md#config.yaml)

- [x] Support [environment variables](https://github.com/CatchZeng/dingtalk#environment%20variables)

- [x] Support sign

<img src="https://dingtalkdoc.oss-cn-beijing.aliyuncs.com/images/0.0.210/1572261283991-f8e35f4d-6997-4a02-9704-843ee8f97464.png" width = 50% />
Expand Down Expand Up @@ -68,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.3.3
go install github.com/CatchZeng/dingtalk@v1.4.0

# Go version < 1.16
go get -u github.com/CatchZeng/dingtalk@v1.3.3
go get -u github.com/CatchZeng/dingtalk@v1.4.0
```

## Usage
Expand All @@ -85,6 +87,14 @@ access_token: "1c53e149ba5de6597cxxxxxx0e901fdxxxxxx80b8ac141e4a75afdc44c85ca4f"
secret: "SECb90923e19e58b466481e9e7b7a5bxxxxxx4531axxxxxxad3967fb29f0eae5c68"
```
### environment variables
```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
```

### Docker

```shell
Expand Down
2 changes: 1 addition & 1 deletion build/package/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.17.6-alpine as builder
FROM golang:1.18.1-alpine as builder
RUN mkdir /build
ADD . /build/
WORKDIR /build
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.3.3"
buildTime = "2022/01/21"
version = "1.4.0"
buildTime = "2022/04/18"
)

// versionCmd represents the version command
Expand Down
10 changes: 10 additions & 0 deletions configs/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package configs

import (
"log"
"os"
"path"
"strings"

"github.com/mitchellh/go-homedir"
"github.com/spf13/viper"
Expand Down Expand Up @@ -32,6 +34,14 @@ func InitConfig() {

// GetConfig get configs with key
func GetConfig(key string) (string, error) {
// Check the environment variable
envKey := strings.ToUpper(key)
result := os.Getenv(envKey)

if result != "" {
return result, nil
}

// If a configs file is found, read it in.
err := viper.ReadInConfig()
if err == nil {
Expand Down
32 changes: 17 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
module github.com/CatchZeng/dingtalk

go 1.17
go 1.18

require (
bou.ke/monkey v1.0.2
github.com/CatchZeng/gutils v0.1.4
github.com/golang/mock v1.4.4
github.com/mitchellh/go-homedir v1.1.0
github.com/spf13/cobra v1.0.0
github.com/spf13/viper v1.7.1
github.com/spf13/cobra v1.4.0
github.com/spf13/viper v1.11.0
)

require (
github.com/fsnotify/fsnotify v1.4.7 // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/magiconair/properties v1.8.1 // indirect
github.com/mitchellh/mapstructure v1.1.2 // indirect
github.com/pelletier/go-toml v1.2.0 // indirect
github.com/spf13/afero v1.1.2 // indirect
github.com/spf13/cast v1.3.0 // indirect
github.com/spf13/jwalterweatherman v1.0.0 // indirect
github.com/spf13/pflag v1.0.3 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/mitchellh/mapstructure v1.4.3 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/pelletier/go-toml/v2 v2.0.0-beta.8 // indirect
github.com/spf13/afero v1.8.2 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0 // indirect
golang.org/x/text v0.3.2 // indirect
gopkg.in/ini.v1 v1.51.0 // indirect
gopkg.in/yaml.v2 v2.2.4 // indirect
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/ini.v1 v1.66.4 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)
Loading

0 comments on commit 9782c51

Please sign in to comment.