From 8bb707776bf510e629df23de83ef7cd4134f1c60 Mon Sep 17 00:00:00 2001 From: MHSanaei Date: Tue, 17 Mar 2026 22:30:05 +0100 Subject: [PATCH] Add Go code analyzer workflow --- .github/workflows/code-analyzer.yml | 58 +++++++++++++++++++++++++++++ web/controller/index.go | 10 ++--- web/service/user.go | 2 +- 3 files changed, 64 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/code-analyzer.yml diff --git a/.github/workflows/code-analyzer.yml b/.github/workflows/code-analyzer.yml new file mode 100644 index 00000000..d37f7bd9 --- /dev/null +++ b/.github/workflows/code-analyzer.yml @@ -0,0 +1,58 @@ +name: Go Code Analyzer + +on: + push: + branches: + - main + paths: + - "**.go" + - go.mod + - go.sum + - ".github/workflows/code-analyzer.yml" + pull_request: + branches: + - main + paths: + - "**.go" + - go.mod + - go.sum + - ".github/workflows/code-analyzer.yml" + +permissions: + contents: read + +jobs: + analyze: + name: Analyze Go code + runs-on: ubuntu-latest + timeout-minutes: 20 + steps: + - name: Checkout repository + uses: actions/checkout@v6 + + - name: Set up Go + uses: actions/setup-go@v6 + with: + go-version-file: go.mod + cache: true + + - name: Check formatting + run: | + unformatted=$(gofmt -l .) + if [ -n "$unformatted" ]; then + echo "These files are not gofmt-formatted:" + echo "$unformatted" + exit 1 + fi + + - name: Run go vet + run: go vet ./... + + - name: Run staticcheck + uses: dominikh/staticcheck-action@v1 + with: + version: "latest" + install-go: false + + - name: Run tests + run: go test -race -shuffle=on ./... diff --git a/web/controller/index.go b/web/controller/index.go index 605f874f..dd58e5e5 100644 --- a/web/controller/index.go +++ b/web/controller/index.go @@ -1,10 +1,10 @@ package controller import ( + "fmt" "net/http" "text/template" "time" - "fmt" "github.com/mhsanaei/3x-ui/v2/logger" "github.com/mhsanaei/3x-ui/v2/web/service" @@ -79,12 +79,12 @@ func (a *IndexController) login(c *gin.Context) { if user == nil { logger.Warningf("wrong username: \"%s\", password: \"%s\", IP: \"%s\"", safeUser, safePass, getRemoteIp(c)) - - notifyPass := safePass - + + notifyPass := safePass + if checkErr != nil && checkErr.Error() == "invalid 2fa code" { translatedError := a.tgbot.I18nBot("tgbot.messages.2faFailed") - notifyPass = fmt.Sprintf("*** (%s)", translatedError) + notifyPass = fmt.Sprintf("*** (%s)", translatedError) } a.tgbot.UserLoginNotify(safeUser, notifyPass, getRemoteIp(c), timeStr, 0) diff --git a/web/service/user.go b/web/service/user.go index 0a2a3f3e..6fcf17e7 100644 --- a/web/service/user.go +++ b/web/service/user.go @@ -95,7 +95,7 @@ func (s *UserService) CheckUser(username string, password string, twoFactorCode } if gotp.NewDefaultTOTP(twoFactorToken).Now() != twoFactorCode { - return nil, errors.New("invalid 2fa code") + return nil, errors.New("invalid 2fa code") } }