Skip to content

Commit

Permalink
ci: add lint workflow (#283)
Browse files Browse the repository at this point in the history
* ci: add lint

Signed-off-by: ashing <[email protected]>

* fix: add timeout

Signed-off-by: ashing <[email protected]>

* fix: EOL

Signed-off-by: ashing <[email protected]>

* fix: EOL

Signed-off-by: ashing <[email protected]>

---------

Signed-off-by: ashing <[email protected]>
  • Loading branch information
ronething committed Feb 23, 2024
1 parent a16bafe commit 5300bfa
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 4 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Lint Check

on:
push:
branches:
- main
- release/**
pull_request:
branches:
- main
- release/**
permissions: read-all
jobs:
gofmt:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v3
- name: Setup Go Environment
uses: actions/setup-go@v3
with:
go-version: '1.20.3'
- name: Run gofmt Check
working-directory: ./
run: |
diffs=`gofmt -l .`
if [[ -n $diffs ]]; then
echo "Files are not formatted by gofmt:"
echo $diffs
exit 1
fi
golint:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- name: Setup Go Environment
uses: actions/setup-go@v3
with:
go-version: '1.20.3'
- name: Download golangci-lint
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.54.2
- name: Run Golang Linters
working-directory: ./
run: |
PATH=${PATH}:$(go env GOPATH)/bin make lint
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ build-linux-arm:
CGO_ENABLED=0 GOARCH=arm64 GOOS=linux go build -o chatgpt-dingtalk main.go

lint:
env GOGC=25 golangci-lint run --fix -j 8 -v ./...
env GOGC=25 golangci-lint run --fix -j 8 --timeout 10m -v ./...

goimports:
@bash ./scripts/goimports-reviser.sh
2 changes: 1 addition & 1 deletion pkg/cache/user_requese.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
// SetUseRequestCount 设置用户请求次数
func (s *UserService) SetUseRequestCount(userId string, current int) {
expiration := time.Now().Add(time.Hour * 24).Truncate(time.Hour * 24)
duration := expiration.Sub(time.Now())
duration := time.Until(expiration)
// 设置缓存失效时间为第二天零点
s.cache.Set(userId+"_request", current, duration)
}
Expand Down
11 changes: 9 additions & 2 deletions pkg/dingbot/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,12 @@ func (c *DingTalkClient) UploadMedia(content []byte, filename, mediaType, mimeTy
return nil, err
}
_, err = part.Write(content)
writer.WriteField("type", mediaType)
if err != nil {
return nil, err
}
if err = writer.WriteField("type", mediaType); err != nil {
return nil, err
}
err = writer.Close()
if err != nil {
return nil, err
Expand All @@ -166,10 +171,12 @@ func (c *DingTalkClient) UploadMedia(content []byte, filename, mediaType, mimeTy
// Parse the response body as JSON and extract the media ID
media := &MediaUploadResult{}
bodyBytes, err := io.ReadAll(res.Body)
json.Unmarshal(bodyBytes, media)
if err != nil {
return nil, err
}
if err = json.Unmarshal(bodyBytes, media); err != nil {
return nil, err
}
if media.ErrorCode != 0 {
return nil, errors.New(media.ErrorMessage)
}
Expand Down

0 comments on commit 5300bfa

Please sign in to comment.