Skip to content

Commit 1c17895

Browse files
authored
refactor: 优化并整理代码 (#12)
* refactor: 优化并整理代码 * fix: actions * fix: actions * fix: actions * fix: actions * fix: test * fix: actions * fix: actions * fix: actions * fix: actions * fix: actions * fix: actions
1 parent 427507f commit 1c17895

28 files changed

+6858
-12875
lines changed

.github/workflows/go-fmt.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ jobs:
2424
build:
2525
runs-on: ubuntu-latest
2626
steps:
27-
- uses: actions/checkout@v3
27+
- uses: actions/checkout@v4
2828
- name: Set up Go
2929
uses: actions/setup-go@v3
3030
with:
31-
go-version: ">=1.20.0"
31+
go-version: '>=1.21.1'
3232

3333
- name: Install goimports
3434
run: go install golang.org/x/tools/cmd/goimports@latest

.github/workflows/go.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ jobs:
2424
build:
2525
runs-on: ubuntu-latest
2626
steps:
27-
- uses: actions/checkout@v3
27+
- uses: actions/checkout@v4
2828
- name: Set up Go
2929
uses: actions/setup-go@v3
3030
with:
31-
go-version: 1.20.0
31+
go-version: '1.21.1'
3232

3333
- name: Build
3434
run: go build -v ./...

.github/workflows/golangci-lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ jobs:
3333
steps:
3434
- uses: actions/setup-go@v3
3535
with:
36-
go-version: 1.20.0
37-
- uses: actions/checkout@v3
36+
go-version: '1.21.1'
37+
- uses: actions/checkout@v4
3838
- name: golangci-lint
3939
uses: golangci/golangci-lint-action@v3
4040
with:
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright 2023 ecodeclub
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: Integration Test
16+
17+
on:
18+
push:
19+
branches: [ main, dev]
20+
pull_request:
21+
branches: [ main, dev]
22+
23+
jobs:
24+
build:
25+
runs-on: ubuntu-latest
26+
steps:
27+
- uses: actions/checkout@v4
28+
- name: Set up Go
29+
uses: actions/setup-go@v2
30+
with:
31+
go-version: '1.21.1'
32+
33+
- name: Test
34+
run: sudo sh ./script/integrate_test.sh

.licenserc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
"**/*.{yml,toml}": "# Copyright 2023 ecodeclub",
44
"**/*.sh": "# Copyright 2023 ecodeclub",
55
"ignore": [
6-
"*.mock.go"
6+
"**/*.mock.go"
77
]
88
}

Makefile

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,41 @@
1-
.PHONY: bench
2-
bench:
3-
@go test -bench=. -benchmem ./...
4-
5-
.PHONY: ut
6-
ut:
7-
@go test -tags=goexperiment.arenas -race ./...
8-
9-
.PHONY: setup
10-
setup:
11-
@sh ./script/setup.sh
12-
13-
.PHONY: fmt
14-
fmt:
15-
@sh ./script/goimports.sh
16-
17-
.PHONY: lint
18-
lint:
19-
@golangci-lint run -c .golangci.yml
20-
21-
.PHONY: tidy
22-
tidy:
23-
@go mod tidy -v
24-
25-
.PHONY: check
26-
check:
27-
@$(MAKE) fmt
28-
@$(MAKE) tidy
1+
.PHONY: bench
2+
bench:
3+
@go test -bench=. -benchmem ./...
4+
5+
.PHONY: ut
6+
ut:
7+
@go test -tags=goexperiment.arenas -race ./...
8+
9+
.PHONY: setup
10+
setup:
11+
@sh ./script/setup.sh
12+
13+
.PHONY: fmt
14+
fmt:
15+
@sh ./script/goimports.sh
16+
17+
.PHONY: lint
18+
lint:
19+
@golangci-lint run -c .golangci.yml
20+
21+
.PHONY: tidy
22+
tidy:
23+
@go mod tidy -v
24+
25+
.PHONY: check
26+
check:
27+
@$(MAKE) fmt
28+
@$(MAKE) tidy
29+
30+
# e2e 测试
31+
.PHONY: e2e
32+
e2e:
33+
sh ./script/integrate_test.sh
34+
35+
.PHONY: e2e_up
36+
e2e_up:
37+
docker compose -f script/integration_test_compose.yml up -d
38+
39+
.PHONY: e2e_down
40+
e2e_down:
41+
docker compose -f script/integration_test_compose.yml down

go.mod

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
module github.com/ecodeclub/ginx
22

3-
go 1.21.1
3+
go 1.21
44

55
require (
66
github.com/ecodeclub/ekit v0.0.8
77
github.com/gin-gonic/gin v1.9.1
88
github.com/golang-jwt/jwt/v5 v5.0.0
9-
github.com/redis/go-redis/v9 v9.1.0
10-
github.com/stretchr/testify v1.8.3
9+
github.com/redis/go-redis/v9 v9.2.1
10+
github.com/stretchr/testify v1.8.4
1111
go.uber.org/atomic v1.11.0
1212
go.uber.org/mock v0.3.0
1313
)
@@ -36,11 +36,9 @@ require (
3636
github.com/ugorji/go/codec v1.2.11 // indirect
3737
golang.org/x/arch v0.3.0 // indirect
3838
golang.org/x/crypto v0.9.0 // indirect
39-
golang.org/x/mod v0.11.0 // indirect
4039
golang.org/x/net v0.10.0 // indirect
4140
golang.org/x/sys v0.8.0 // indirect
4241
golang.org/x/text v0.9.0 // indirect
43-
golang.org/x/tools v0.6.0 // indirect
4442
google.golang.org/protobuf v1.30.0 // indirect
4543
gopkg.in/yaml.v3 v3.0.1 // indirect
4644
)

go.sum

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
github.com/bsm/ginkgo/v2 v2.9.5 h1:rtVBYPs3+TC5iLUVOis1B9tjLTup7Cj5IfzosKtvTJ0=
2-
github.com/bsm/ginkgo/v2 v2.9.5/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
3-
github.com/bsm/gomega v1.26.0 h1:LhQm+AFcgV2M0WyKroMASzAzCAJVpAxQXv4SaI9a69Y=
4-
github.com/bsm/gomega v1.26.0/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
1+
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
2+
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
3+
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
4+
github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
55
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
66
github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s=
77
github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U=
@@ -61,8 +61,8 @@ github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZ
6161
github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4=
6262
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
6363
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
64-
github.com/redis/go-redis/v9 v9.1.0 h1:137FnGdk+EQdCbye1FW+qOEcY5S+SpY9T0NiuqvtfMY=
65-
github.com/redis/go-redis/v9 v9.1.0/go.mod h1:urWj3He21Dj5k4TK1y59xH8Uj6ATueP8AH1cY3lZl4c=
64+
github.com/redis/go-redis/v9 v9.2.1 h1:WlYJg71ODF0dVspZZCpYmoF1+U1Jjk9Rwd7pq6QmlCg=
65+
github.com/redis/go-redis/v9 v9.2.1/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M=
6666
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
6767
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
6868
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
@@ -72,8 +72,9 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
7272
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
7373
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
7474
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
75-
github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=
7675
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
76+
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
77+
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
7778
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
7879
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
7980
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
@@ -87,8 +88,6 @@ golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k=
8788
golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
8889
golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g=
8990
golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0=
90-
golang.org/x/mod v0.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU=
91-
golang.org/x/mod v0.11.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
9291
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
9392
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
9493
golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
@@ -97,8 +96,6 @@ golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
9796
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
9897
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
9998
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
100-
golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM=
101-
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
10299
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
103100
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
104101
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=

internal/integration/activelimit_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ package integration
1919
import (
2020
"context"
2121
"fmt"
22-
"github.com/ecodeclub/ginx/middlewares/activelimit/redislimit"
23-
"github.com/redis/go-redis/v9"
2422
"net/http"
2523
"net/http/httptest"
2624
"testing"
2725
"time"
2826

27+
"github.com/ecodeclub/ginx/middlewares/activelimit/redislimit"
28+
"github.com/redis/go-redis/v9"
29+
2930
"github.com/gin-gonic/gin"
3031
"github.com/stretchr/testify/assert"
3132
"github.com/stretchr/testify/require"

0 commit comments

Comments
 (0)