Bladeren bron

feat: 代码格式化

BaiLuoYan 1 uur geleden
bovenliggende
commit
912fd5d29a
38 gewijzigde bestanden met toevoegingen van 197 en 167 verwijderingen
  1. 1 2
      internal/config/config.go
  2. 3 2
      internal/loaders/userDetailsLoader.go
  3. 7 6
      internal/loaders/userDetailsLoader_test.go
  4. 5 4
      internal/logic/auth/access_test.go
  5. 5 4
      internal/logic/auth/changePasswordLogic_test.go
  6. 4 3
      internal/logic/auth/jwt_test.go
  7. 6 5
      internal/logic/auth/logoutLogic_test.go
  8. 8 2
      internal/logic/dept/createDeptLogic_mock_test.go
  9. 3 2
      internal/logic/dept/createDeptLogic_test.go
  10. 6 4
      internal/logic/member/updateMemberLogic_test.go
  11. 3 3
      internal/logic/product/createProductLogic.go
  12. 8 7
      internal/logic/product/createProductLogic_test.go
  13. 1 0
      internal/logic/product/updateProductLogic_test.go
  14. 0 1
      internal/logic/pub/capEndpointLogic.go
  15. 0 1
      internal/logic/pub/loginByCapLogic_test.go
  16. 10 10
      internal/logic/pub/loginLogic.go
  17. 0 1
      internal/logic/pub/loginLogic_captcha_test.go
  18. 3 2
      internal/logic/pub/loginService_test.go
  19. 5 4
      internal/logic/pub/refreshTokenLogic_test.go
  20. 7 6
      internal/logic/pub/syncPermsLogic_test.go
  21. 3 2
      internal/logic/role/roleDetailLogic_test.go
  22. 3 2
      internal/logic/user/bindRolesLogic_test.go
  23. 4 3
      internal/logic/user/createUserLogic_test.go
  24. 5 4
      internal/logic/user/setUserPermsLogic_test.go
  25. 3 2
      internal/logic/user/updateUserStatusLogic_test.go
  26. 0 1
      internal/middleware/jwtauthMiddleware.go
  27. 6 5
      internal/middleware/jwtauthMiddleware_test.go
  28. 5 4
      internal/middleware/ratelimitMiddleware_test.go
  29. 4 3
      internal/model/dept/sysDeptModel_test.go
  30. 5 4
      internal/model/perm/sysPermModel_test.go
  31. 6 5
      internal/model/product/sysProductModel_test.go
  32. 5 4
      internal/model/productmember/sysProductMemberModel_test.go
  33. 5 4
      internal/model/role/sysRoleModel_test.go
  34. 6 5
      internal/model/user/sysUserModel_test.go
  35. 6 5
      internal/model/userrole/sysUserRoleModel_test.go
  36. 3 3
      internal/response/response.go
  37. 12 11
      internal/server/permserver_test.go
  38. 31 31
      internal/svc/servicecontext.go

+ 1 - 2
internal/config/config.go

@@ -30,7 +30,7 @@ type MinioConf struct {
 	AccessKeySecret string
 	Endpoint        string
 	Domain          string
-	UseSSL          bool                        `json:",default=false"`
+	UseSSL          bool                         `json:",default=false"`
 	FileType        map[string]MinioFileTypeConf `json:",optional"`
 }
 
@@ -58,4 +58,3 @@ type Config struct {
 
 	BehindProxy bool `json:",optional"`
 }
-

+ 3 - 2
internal/loaders/userDetailsLoader.go

@@ -272,8 +272,9 @@ func (l *UserDetailsLoader) CleanByProduct(ctx context.Context, productCode stri
 // 审计 M-N2:历史实现对每个用户串行调用 unregisterCacheKey,触发 2N 次 SREM 串行 RTT,
 // "角色下绑千人"的业务场景里会把 UpdateRole / BindRoles 的尾延迟抬到秒级;更糟糕的是
 // go-zero 的请求 ctx 超时兜不住时会命中"DB 已更新但缓存未清"分支。改为:
-//   (1) 主 key 批 DEL(和原来一致,一次 RTT);
-//   (2) 所有 userIndex / productIndex 的 SREM 合进一次 Pipelined RTT,把 2N 串行压到常数。
+//
+//	(1) 主 key 批 DEL(和原来一致,一次 RTT);
+//	(2) 所有 userIndex / productIndex 的 SREM 合进一次 Pipelined RTT,把 2N 串行压到常数。
 func (l *UserDetailsLoader) BatchDel(ctx context.Context, userIds []int64, productCode string) {
 	if len(userIds) == 0 {
 		return

+ 7 - 6
internal/loaders/userDetailsLoader_test.go

@@ -6,12 +6,6 @@ import (
 	"encoding/json"
 	"errors"
 	"fmt"
-	"github.com/stretchr/testify/assert"
-	"github.com/stretchr/testify/require"
-	"github.com/zeromicro/go-zero/core/stores/cache"
-	"github.com/zeromicro/go-zero/core/stores/redis"
-	"github.com/zeromicro/go-zero/core/stores/sqlx"
-	"golang.org/x/crypto/bcrypt"
 	"math"
 	"math/rand"
 	"perms-system-server/internal/consts"
@@ -31,6 +25,13 @@ import (
 	"sync/atomic"
 	"testing"
 	"time"
+
+	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
+	"github.com/zeromicro/go-zero/core/stores/cache"
+	"github.com/zeromicro/go-zero/core/stores/redis"
+	"github.com/zeromicro/go-zero/core/stores/sqlx"
+	"golang.org/x/crypto/bcrypt"
 )
 
 var testCacheConf = cache.CacheConf{

+ 5 - 4
internal/logic/auth/access_test.go

@@ -4,10 +4,6 @@ import (
 	"context"
 	"errors"
 	"fmt"
-	"github.com/stretchr/testify/assert"
-	"github.com/stretchr/testify/require"
-	"github.com/zeromicro/go-zero/core/stores/sqlx"
-	"go.uber.org/mock/gomock"
 	"math"
 	"math/rand"
 	"perms-system-server/internal/consts"
@@ -23,6 +19,11 @@ import (
 	"perms-system-server/internal/testutil/mocks"
 	"testing"
 	"time"
+
+	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
+	"github.com/zeromicro/go-zero/core/stores/sqlx"
+	"go.uber.org/mock/gomock"
 )
 
 // =====================================================================

+ 5 - 4
internal/logic/auth/changePasswordLogic_test.go

@@ -4,10 +4,6 @@ import (
 	"context"
 	"database/sql"
 	"errors"
-	"github.com/stretchr/testify/assert"
-	"github.com/stretchr/testify/require"
-	"go.uber.org/mock/gomock"
-	"golang.org/x/crypto/bcrypt"
 	"perms-system-server/internal/consts"
 	"perms-system-server/internal/loaders"
 	"perms-system-server/internal/middleware"
@@ -20,6 +16,11 @@ import (
 	"strings"
 	"testing"
 	"time"
+
+	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
+	"go.uber.org/mock/gomock"
+	"golang.org/x/crypto/bcrypt"
 )
 
 func ctxWithUserId(userId int64) context.Context {

+ 4 - 3
internal/logic/auth/jwt_test.go

@@ -5,14 +5,15 @@ import (
 	"crypto/sha256"
 	"encoding/base64"
 	"encoding/json"
-	"github.com/golang-jwt/jwt/v4"
-	"github.com/stretchr/testify/assert"
-	"github.com/stretchr/testify/require"
 	"perms-system-server/internal/consts"
 	"perms-system-server/internal/middleware"
 	"strings"
 	"testing"
 	"time"
+
+	"github.com/golang-jwt/jwt/v4"
+	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
 )
 
 const testSecret = "test-jwt-secret-key"

+ 6 - 5
internal/logic/auth/logoutLogic_test.go

@@ -4,11 +4,6 @@ import (
 	"context"
 	"database/sql"
 	"errors"
-	"github.com/stretchr/testify/assert"
-	"github.com/stretchr/testify/require"
-	"github.com/zeromicro/go-zero/core/limit"
-	"github.com/zeromicro/go-zero/core/stores/redis"
-	"go.uber.org/mock/gomock"
 	"perms-system-server/internal/loaders"
 	"perms-system-server/internal/middleware"
 	userModel "perms-system-server/internal/model/user"
@@ -18,6 +13,12 @@ import (
 	"perms-system-server/internal/testutil/mocks"
 	"testing"
 	"time"
+
+	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
+	"github.com/zeromicro/go-zero/core/limit"
+	"github.com/zeromicro/go-zero/core/stores/redis"
+	"go.uber.org/mock/gomock"
 )
 
 func TestLogout_Normal_IncrementsTokenVersion(t *testing.T) {

+ 8 - 2
internal/logic/dept/createDeptLogic_mock_test.go

@@ -61,7 +61,10 @@ func TestCreateDept_Mock_DefaultDeptType(t *testing.T) {
 			return fn(ctx, nil)
 		})
 	mockDept.EXPECT().InsertWithTx(gomock.Any(), nil, gomock.Any()).
-		DoAndReturn(func(ctx context.Context, s sqlx.Session, data *deptModel.SysDept) (interface{ LastInsertId() (int64, error); RowsAffected() (int64, error) }, error) {
+		DoAndReturn(func(ctx context.Context, s sqlx.Session, data *deptModel.SysDept) (interface {
+			LastInsertId() (int64, error)
+			RowsAffected() (int64, error)
+		}, error) {
 			assert.Equal(t, "NORMAL", data.DeptType)
 			return fakeResult{id: 99}, nil
 		})
@@ -91,7 +94,10 @@ func TestCreateDept_Mock_DevDeptType(t *testing.T) {
 			return fn(ctx, nil)
 		})
 	mockDept.EXPECT().InsertWithTx(gomock.Any(), nil, gomock.Any()).
-		DoAndReturn(func(ctx context.Context, s sqlx.Session, data *deptModel.SysDept) (interface{ LastInsertId() (int64, error); RowsAffected() (int64, error) }, error) {
+		DoAndReturn(func(ctx context.Context, s sqlx.Session, data *deptModel.SysDept) (interface {
+			LastInsertId() (int64, error)
+			RowsAffected() (int64, error)
+		}, error) {
 			assert.Equal(t, "DEV", data.DeptType)
 			return fakeResult{id: 100}, nil
 		})

+ 3 - 2
internal/logic/dept/createDeptLogic_test.go

@@ -5,8 +5,6 @@ import (
 	"errors"
 	"fmt"
 	"math"
-	"github.com/stretchr/testify/assert"
-	"github.com/stretchr/testify/require"
 	"perms-system-server/internal/consts"
 	deptModel "perms-system-server/internal/model/dept"
 	"perms-system-server/internal/response"
@@ -18,6 +16,9 @@ import (
 	"sync/atomic"
 	"testing"
 	"time"
+
+	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
 )
 
 func insertDeptRaw(ctx context.Context, svcCtx *svc.ServiceContext, parentId int64, name, path string) (int64, error) {

+ 6 - 4
internal/logic/member/updateMemberLogic_test.go

@@ -4,9 +4,6 @@ import (
 	"database/sql"
 	"errors"
 	"fmt"
-	"github.com/stretchr/testify/assert"
-	"github.com/stretchr/testify/require"
-	"github.com/zeromicro/go-zero/core/stores/redis"
 	"perms-system-server/internal/consts"
 	productModel "perms-system-server/internal/model/product"
 	memberModel "perms-system-server/internal/model/productmember"
@@ -18,6 +15,10 @@ import (
 	"perms-system-server/internal/types"
 	"testing"
 	"time"
+
+	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
+	"github.com/zeromicro/go-zero/core/stores/redis"
 )
 
 func TestUpdateMember_Normal(t *testing.T) {
@@ -514,7 +515,8 @@ func seedSecondActiveAdmin(t *testing.T, svcCtx *svc.ServiceContext, productCode
 // TC-1130:降级 ADMIN→MEMBER 时 sys_user.tokenVersion 严格 +1(M-R15-1 方案 A)。
 // 断言 1:tv_after == tv_before + 1;
 // 断言 2:同事务落盘——若 UPDATE 成员成功但 tokenVersion 未增(或相反),就代表
-//         IncrementTokenVersionWithTx 脱离了业务事务,必须立刻暴露。
+//
+//	IncrementTokenVersionWithTx 脱离了业务事务,必须立刻暴露。
 func TestUpdateMember_DemoteAdminToMember_BumpsTokenVersion(t *testing.T) {
 	ctx := ctxhelper.SuperAdminCtx()
 	svcCtx := svc.NewServiceContext(testutil.GetTestConfig())

+ 3 - 3
internal/logic/product/createProductLogic.go

@@ -159,9 +159,9 @@ func (l *CreateProductLogic) CreateProduct(req *types.CreateProductReq) (resp *t
 		productId, _ = result.LastInsertId()
 
 		userResult, err := l.svcCtx.SysUserModel.InsertWithTx(ctx, session, &userModel.SysUser{
-			Username:           adminUsername,
-			Password:           string(hashedPwd),
-			Nickname:           fmt.Sprintf("%s管理员", req.Name),
+			Username: adminUsername,
+			Password: string(hashedPwd),
+			Nickname: fmt.Sprintf("%s管理员", req.Name),
 			// 审计 L-R17-2:与 CreateUser 对齐,显式声明 Avatar NULL,避免依赖 Go 结构体零值
 			// 在未来字段类型重构时静默漂移(见 createUserLogic.go 对应注释)。
 			Avatar:             sql.NullString{Valid: false},

+ 8 - 7
internal/logic/product/createProductLogic_test.go

@@ -5,13 +5,6 @@ import (
 	"database/sql"
 	"encoding/json"
 	"errors"
-	"github.com/go-sql-driver/mysql"
-	"github.com/stretchr/testify/assert"
-	"github.com/stretchr/testify/require"
-	"github.com/zeromicro/go-zero/core/stores/redis"
-	"github.com/zeromicro/go-zero/core/stores/sqlx"
-	"go.uber.org/mock/gomock"
-	"golang.org/x/crypto/bcrypt"
 	deptModel "perms-system-server/internal/model/dept"
 	productModel "perms-system-server/internal/model/product"
 	userModel "perms-system-server/internal/model/user"
@@ -24,6 +17,14 @@ import (
 	"sync"
 	"testing"
 	"time"
+
+	"github.com/go-sql-driver/mysql"
+	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
+	"github.com/zeromicro/go-zero/core/stores/redis"
+	"github.com/zeromicro/go-zero/core/stores/sqlx"
+	"go.uber.org/mock/gomock"
+	"golang.org/x/crypto/bcrypt"
 )
 
 func TestCreateProduct_Success(t *testing.T) {

+ 1 - 0
internal/logic/product/updateProductLogic_test.go

@@ -169,6 +169,7 @@ func TestUpdateProduct_InvalidStatusRejected(t *testing.T) {
 // seedProductWithMembers 构造一个启用中的产品,附带若干成员:
 //   - memberSpec 每项是 {memberType, status},按顺序 seed;
 //   - 返回产品及各 userId(顺序对应入参)。
+//
 // 统一用 UniqueId 避免与既有数据冲突;t.Cleanup 里按 productCode 清理成员,再删用户/产品。
 type memberSpec struct {
 	MemberType string

+ 0 - 1
internal/logic/pub/capEndpointLogic.go

@@ -36,4 +36,3 @@ func (l *CapEndpointLogic) CapEndpoint() (*types.CapEndpointResp, error) {
 	url := cfg.EndpointURL + "/" + cfg.Key + "/"
 	return &types.CapEndpointResp{Data: url}, nil
 }
-

+ 0 - 1
internal/logic/pub/loginByCapLogic_test.go

@@ -203,4 +203,3 @@ func TestLoginByCap_ValidToken_SuperAdminRejected(t *testing.T) {
 	require.True(t, errors.As(err, &codeErr))
 	assert.Equal(t, 403, codeErr.Code())
 }
-

+ 10 - 10
internal/logic/pub/loginLogic.go

@@ -45,16 +45,16 @@ func (l *LoginLogic) Login(req *types.LoginReq) (resp *types.LoginResp, err erro
 	result, err := ValidateProductLogin(l.ctx, l.svcCtx, req.Username, req.Password, req.ProductCode, clientIP)
 	if err != nil {
 		if le, ok := err.(*LoginError); ok {
-		switch le.Code {
-		case 400:
-			return nil, response.ErrBadRequest(le.Message)
-		case 401:
-			return nil, response.ErrUnauthorized(le.Message)
-		case 403:
-			return nil, response.ErrForbidden(le.Message)
-		case 429:
-			return nil, response.NewCodeError(429, le.Message)
-		}
+			switch le.Code {
+			case 400:
+				return nil, response.ErrBadRequest(le.Message)
+			case 401:
+				return nil, response.ErrUnauthorized(le.Message)
+			case 403:
+				return nil, response.ErrForbidden(le.Message)
+			case 429:
+				return nil, response.NewCodeError(429, le.Message)
+			}
 		}
 		return nil, err
 	}

+ 0 - 1
internal/logic/pub/loginLogic_captcha_test.go

@@ -126,4 +126,3 @@ func TestLogin_CapEnabled_Rejected(t *testing.T) {
 	assert.Equal(t, 400, codeErr.Code())
 	assert.Contains(t, codeErr.Error(), "当前已启用人机验证")
 }
-

+ 3 - 2
internal/logic/pub/loginService_test.go

@@ -3,12 +3,13 @@ package pub
 import (
 	"context"
 	"errors"
+	"perms-system-server/internal/testutil"
+	"testing"
+
 	"github.com/stretchr/testify/assert"
 	"github.com/stretchr/testify/require"
 	"github.com/zeromicro/go-zero/core/limit"
 	"github.com/zeromicro/go-zero/core/stores/redis"
-	"perms-system-server/internal/testutil"
-	"testing"
 )
 
 // TC-0838: 冻结用户 + 错误密码 —— 不得返回 403,必须与"用户不存在"合并为 401

+ 5 - 4
internal/logic/pub/refreshTokenLogic_test.go

@@ -4,10 +4,6 @@ import (
 	"context"
 	"database/sql"
 	"errors"
-	"github.com/stretchr/testify/assert"
-	"github.com/stretchr/testify/require"
-	"github.com/zeromicro/go-zero/core/limit"
-	"github.com/zeromicro/go-zero/core/stores/redis"
 	authHelper "perms-system-server/internal/logic/auth"
 	"perms-system-server/internal/middleware"
 	permModel "perms-system-server/internal/model/perm"
@@ -20,6 +16,11 @@ import (
 	"sync/atomic"
 	"testing"
 	"time"
+
+	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
+	"github.com/zeromicro/go-zero/core/limit"
+	"github.com/zeromicro/go-zero/core/stores/redis"
 )
 
 func insertRefreshTestUser(t *testing.T, ctx context.Context, username, password string, status, isSuperAdmin int64) (int64, func()) {

+ 7 - 6
internal/logic/pub/syncPermsLogic_test.go

@@ -4,12 +4,6 @@ import (
 	"context"
 	"errors"
 	"fmt"
-	"github.com/stretchr/testify/assert"
-	"github.com/stretchr/testify/require"
-	"github.com/zeromicro/go-zero/core/stores/redis"
-	"github.com/zeromicro/go-zero/core/stores/sqlx"
-	"go.uber.org/mock/gomock"
-	"golang.org/x/crypto/bcrypt"
 	permModel "perms-system-server/internal/model/perm"
 	productModel "perms-system-server/internal/model/product"
 	"perms-system-server/internal/response"
@@ -18,6 +12,13 @@ import (
 	"perms-system-server/internal/types"
 	"testing"
 	"time"
+
+	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
+	"github.com/zeromicro/go-zero/core/stores/redis"
+	"github.com/zeromicro/go-zero/core/stores/sqlx"
+	"go.uber.org/mock/gomock"
+	"golang.org/x/crypto/bcrypt"
 )
 
 func insertSyncTestProduct(t *testing.T, ctx context.Context, code, appKey, appSecret string, status int64) (int64, func()) {

+ 3 - 2
internal/logic/role/roleDetailLogic_test.go

@@ -2,8 +2,6 @@ package role
 
 import (
 	"errors"
-	"github.com/stretchr/testify/assert"
-	"github.com/stretchr/testify/require"
 	permModel "perms-system-server/internal/model/perm"
 	roleModel "perms-system-server/internal/model/role"
 	"perms-system-server/internal/model/roleperm"
@@ -14,6 +12,9 @@ import (
 	"perms-system-server/internal/types"
 	"testing"
 	"time"
+
+	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
 )
 
 func TestRoleDetail_Normal(t *testing.T) {

+ 3 - 2
internal/logic/user/bindRolesLogic_test.go

@@ -4,8 +4,6 @@ import (
 	"context"
 	"errors"
 	"fmt"
-	"github.com/stretchr/testify/assert"
-	"github.com/stretchr/testify/require"
 	"math"
 	"perms-system-server/internal/consts"
 	"perms-system-server/internal/loaders"
@@ -24,6 +22,9 @@ import (
 	"sync/atomic"
 	"testing"
 	"time"
+
+	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
 )
 
 func insertTestMember(t *testing.T, svcCtx *svc.ServiceContext, productCode string, userId int64) int64 {

+ 4 - 3
internal/logic/user/createUserLogic_test.go

@@ -4,8 +4,6 @@ import (
 	"context"
 	"database/sql"
 	"errors"
-	"github.com/stretchr/testify/assert"
-	"github.com/stretchr/testify/require"
 	"math"
 	"perms-system-server/internal/consts"
 	"perms-system-server/internal/loaders"
@@ -23,6 +21,9 @@ import (
 	"testing"
 	"time"
 
+	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
+
 	"github.com/zeromicro/go-zero/core/stores/sqlx"
 	"go.uber.org/mock/gomock"
 )
@@ -872,7 +873,7 @@ func TestCreateUser_L_R17_1_ReservedUsernamePrefix_SuperAdminAllowed(t *testing.
 // logic 在 `SysUser{...}` 字面量里必须显式 `Avatar: sql.NullString{Valid: false}`。
 // 行为上 Go 结构体零值也是 `{Valid:false, String:""}`——它确实写 NULL;但显式写出来的
 // 实际意义是"未来如有人把 SysUser.Avatar 改成 string 类型,该字面量立刻编译失败,
-// 避免零值依赖在字段迁移时静默漂移到落 `''` 空串,与历史 NULL 行并存产生脏数据"。
+// 避免零值依赖在字段迁移时静默漂移到落 `` 空串,与历史 NULL 行并存产生脏数据"。
 func TestCreateUser_L_R17_2_AvatarExplicitNull(t *testing.T) {
 	ctx := ctxhelper.SuperAdminCtx()
 	svcCtx := svc.NewServiceContext(testutil.GetTestConfig())

+ 5 - 4
internal/logic/user/setUserPermsLogic_test.go

@@ -3,16 +3,13 @@ package user
 import (
 	"context"
 	"errors"
-	"github.com/stretchr/testify/assert"
-	"github.com/stretchr/testify/require"
-	"github.com/zeromicro/go-zero/core/stores/sqlx"
 	"math"
 	"perms-system-server/internal/consts"
 	"perms-system-server/internal/loaders"
 	"perms-system-server/internal/middleware"
-	memberModel "perms-system-server/internal/model/productmember"
 	permModel "perms-system-server/internal/model/perm"
 	productModel "perms-system-server/internal/model/product"
+	memberModel "perms-system-server/internal/model/productmember"
 	"perms-system-server/internal/response"
 	"perms-system-server/internal/svc"
 	"perms-system-server/internal/testutil"
@@ -20,6 +17,10 @@ import (
 	"perms-system-server/internal/types"
 	"testing"
 	"time"
+
+	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
+	"github.com/zeromicro/go-zero/core/stores/sqlx"
 )
 
 type userPermRow struct {

+ 3 - 2
internal/logic/user/updateUserStatusLogic_test.go

@@ -4,8 +4,6 @@ import (
 	"context"
 	"database/sql"
 	"errors"
-	"github.com/stretchr/testify/assert"
-	"github.com/stretchr/testify/require"
 	"perms-system-server/internal/consts"
 	"perms-system-server/internal/loaders"
 	"perms-system-server/internal/middleware"
@@ -17,6 +15,9 @@ import (
 	"perms-system-server/internal/types"
 	"testing"
 	"time"
+
+	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
 )
 
 func ctxWithUserId(userId int64) context.Context {

+ 0 - 1
internal/middleware/jwtauthMiddleware.go

@@ -151,4 +151,3 @@ func GetProductCode(ctx context.Context) string {
 	}
 	return ""
 }
-

+ 6 - 5
internal/middleware/jwtauthMiddleware_test.go

@@ -7,11 +7,6 @@ import (
 	"database/sql"
 	"encoding/base64"
 	"encoding/json"
-	"github.com/golang-jwt/jwt/v4"
-	"github.com/stretchr/testify/assert"
-	"github.com/stretchr/testify/require"
-	"github.com/zeromicro/go-zero/core/stores/redis"
-	"github.com/zeromicro/go-zero/rest/httpx"
 	"net/http"
 	"net/http/httptest"
 	"perms-system-server/internal/consts"
@@ -26,6 +21,12 @@ import (
 	"perms-system-server/internal/testutil"
 	"testing"
 	"time"
+
+	"github.com/golang-jwt/jwt/v4"
+	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
+	"github.com/zeromicro/go-zero/core/stores/redis"
+	"github.com/zeromicro/go-zero/rest/httpx"
 )
 
 const testAccessSecret = "test-middleware-secret"

+ 5 - 4
internal/middleware/ratelimitMiddleware_test.go

@@ -3,10 +3,6 @@ package middleware
 import (
 	"encoding/json"
 	"fmt"
-	"github.com/stretchr/testify/assert"
-	"github.com/stretchr/testify/require"
-	"github.com/zeromicro/go-zero/core/stores/redis"
-	"github.com/zeromicro/go-zero/rest/httpx"
 	"math/rand"
 	"net/http"
 	"net/http/httptest"
@@ -14,6 +10,11 @@ import (
 	"perms-system-server/internal/testutil"
 	"testing"
 	"time"
+
+	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
+	"github.com/zeromicro/go-zero/core/stores/redis"
+	"github.com/zeromicro/go-zero/rest/httpx"
 )
 
 func init() {

+ 4 - 3
internal/model/dept/sysDeptModel_test.go

@@ -3,14 +3,15 @@ package dept
 import (
 	"context"
 	"errors"
-	"github.com/stretchr/testify/assert"
-	"github.com/stretchr/testify/require"
-	"github.com/zeromicro/go-zero/core/stores/sqlx"
 	"perms-system-server/internal/testutil"
 	"sync"
 	"sync/atomic"
 	"testing"
 	"time"
+
+	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
+	"github.com/zeromicro/go-zero/core/stores/sqlx"
 )
 
 func TestSysDeptModel_CRUD(t *testing.T) {

+ 5 - 4
internal/model/perm/sysPermModel_test.go

@@ -3,15 +3,16 @@ package perm_test
 import (
 	"context"
 	"errors"
-	"github.com/go-sql-driver/mysql"
-	"github.com/stretchr/testify/assert"
-	"github.com/stretchr/testify/require"
-	"github.com/zeromicro/go-zero/core/stores/sqlx"
 	"perms-system-server/internal/model/perm"
 	"perms-system-server/internal/testutil"
 	"sort"
 	"testing"
 	"time"
+
+	"github.com/go-sql-driver/mysql"
+	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
+	"github.com/zeromicro/go-zero/core/stores/sqlx"
 )
 
 func newTestSysPermModel(t *testing.T) perm.SysPermModel {

+ 6 - 5
internal/model/product/sysProductModel_test.go

@@ -4,17 +4,18 @@ import (
 	"context"
 	"errors"
 	"fmt"
-	"github.com/go-sql-driver/mysql"
-	"github.com/stretchr/testify/assert"
-	"github.com/stretchr/testify/require"
-	"github.com/zeromicro/go-zero/core/stores/redis"
-	"github.com/zeromicro/go-zero/core/stores/sqlx"
 	"perms-system-server/internal/testutil"
 	"strings"
 	"sync"
 	"sync/atomic"
 	"testing"
 	"time"
+
+	"github.com/go-sql-driver/mysql"
+	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
+	"github.com/zeromicro/go-zero/core/stores/redis"
+	"github.com/zeromicro/go-zero/core/stores/sqlx"
 )
 
 func newTestModel(t *testing.T) SysProductModel {

+ 5 - 4
internal/model/productmember/sysProductMemberModel_test.go

@@ -3,15 +3,16 @@ package productmember
 import (
 	"context"
 	"errors"
-	"github.com/go-sql-driver/mysql"
-	"github.com/stretchr/testify/assert"
-	"github.com/stretchr/testify/require"
-	"github.com/zeromicro/go-zero/core/stores/sqlx"
 	"math/rand"
 	"perms-system-server/internal/consts"
 	"perms-system-server/internal/testutil"
 	"testing"
 	"time"
+
+	"github.com/go-sql-driver/mysql"
+	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
+	"github.com/zeromicro/go-zero/core/stores/sqlx"
 )
 
 func randProductMemberUserId() int64 {

+ 5 - 4
internal/model/role/sysRoleModel_test.go

@@ -3,16 +3,17 @@ package role
 import (
 	"context"
 	"errors"
-	"github.com/go-sql-driver/mysql"
-	"github.com/stretchr/testify/assert"
-	"github.com/stretchr/testify/require"
-	"github.com/zeromicro/go-zero/core/stores/sqlx"
 	"math"
 	"perms-system-server/internal/consts"
 	"perms-system-server/internal/testutil"
 	"strings"
 	"testing"
 	"time"
+
+	"github.com/go-sql-driver/mysql"
+	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
+	"github.com/zeromicro/go-zero/core/stores/sqlx"
 )
 
 func TestSysRoleModel_CRUD(t *testing.T) {

+ 6 - 5
internal/model/user/sysUserModel_test.go

@@ -5,11 +5,6 @@ import (
 	"database/sql"
 	"errors"
 	"fmt"
-	"github.com/go-sql-driver/mysql"
-	"github.com/stretchr/testify/assert"
-	"github.com/stretchr/testify/require"
-	"github.com/zeromicro/go-zero/core/stores/redis"
-	"github.com/zeromicro/go-zero/core/stores/sqlx"
 	"perms-system-server/internal/model/user"
 	"perms-system-server/internal/testutil"
 	"strings"
@@ -17,6 +12,12 @@ import (
 	"sync/atomic"
 	"testing"
 	"time"
+
+	"github.com/go-sql-driver/mysql"
+	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
+	"github.com/zeromicro/go-zero/core/stores/redis"
+	"github.com/zeromicro/go-zero/core/stores/sqlx"
 )
 
 func newTestSysUser(username string, deptId int64) *user.SysUser {

+ 6 - 5
internal/model/userrole/sysUserRoleModel_test.go

@@ -4,16 +4,17 @@ import (
 	"context"
 	"errors"
 	"fmt"
-	"github.com/go-sql-driver/mysql"
-	"github.com/stretchr/testify/assert"
-	"github.com/stretchr/testify/require"
-	"github.com/zeromicro/go-zero/core/stores/redis"
-	"github.com/zeromicro/go-zero/core/stores/sqlx"
 	"math/rand"
 	"perms-system-server/internal/testutil"
 	"sort"
 	"testing"
 	"time"
+
+	"github.com/go-sql-driver/mysql"
+	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
+	"github.com/zeromicro/go-zero/core/stores/redis"
+	"github.com/zeromicro/go-zero/core/stores/sqlx"
 )
 
 func randUserRoleId() int64 {

+ 3 - 3
internal/response/response.go

@@ -49,9 +49,9 @@ func NewCodeError(code int, msg string) *CodeError {
 	return &CodeError{code: code, msg: msg, showType: ShowTypeErrorMessage}
 }
 
-func (e *CodeError) Error() string    { return e.msg }
-func (e *CodeError) Code() int        { return e.code }
-func (e *CodeError) ShowType() int    { return e.showType }
+func (e *CodeError) Error() string { return e.msg }
+func (e *CodeError) Code() int     { return e.code }
+func (e *CodeError) ShowType() int { return e.showType }
 
 func ErrBadRequest(msg string) *CodeError      { return NewCodeError(400, msg) }
 func ErrUnauthorized(msg string) *CodeError    { return NewCodeError(401, msg) }

+ 12 - 11
internal/server/permserver_test.go

@@ -4,17 +4,6 @@ import (
 	"context"
 	"database/sql"
 	"fmt"
-	"github.com/golang-jwt/jwt/v4"
-	"github.com/stretchr/testify/assert"
-	"github.com/stretchr/testify/require"
-	"github.com/zeromicro/go-zero/core/limit"
-	"github.com/zeromicro/go-zero/core/stores/redis"
-	"github.com/zeromicro/go-zero/core/stores/sqlx"
-	"go.uber.org/mock/gomock"
-	"golang.org/x/crypto/bcrypt"
-	"google.golang.org/grpc/codes"
-	"google.golang.org/grpc/peer"
-	"google.golang.org/grpc/status"
 	"net"
 	authHelper "perms-system-server/internal/logic/auth"
 	pubLogic "perms-system-server/internal/logic/pub"
@@ -34,6 +23,18 @@ import (
 	"perms-system-server/pb"
 	"testing"
 	"time"
+
+	"github.com/golang-jwt/jwt/v4"
+	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
+	"github.com/zeromicro/go-zero/core/limit"
+	"github.com/zeromicro/go-zero/core/stores/redis"
+	"github.com/zeromicro/go-zero/core/stores/sqlx"
+	"go.uber.org/mock/gomock"
+	"golang.org/x/crypto/bcrypt"
+	"google.golang.org/grpc/codes"
+	"google.golang.org/grpc/peer"
+	"google.golang.org/grpc/status"
 )
 
 func bcryptHash(t *testing.T, plaintext string) string {

+ 31 - 31
internal/svc/servicecontext.go

@@ -16,22 +16,22 @@ import (
 )
 
 type ServiceContext struct {
-	Config                config.Config
-	JwtAuth               rest.Middleware
-	ProductLoginRateLimit rest.Middleware
-	AdminLoginRateLimit   rest.Middleware
-	SyncRateLimit         rest.Middleware
-	RefreshTokenRateLimit rest.Middleware
-	GrpcLoginLimiter      *limit.PeriodLimit
-	GrpcRefreshLimiter    *limit.PeriodLimit
-	GrpcVerifyLimiter     *limit.PeriodLimit
-	GrpcSyncLimiter       *limit.PeriodLimit
+	Config                  config.Config
+	JwtAuth                 rest.Middleware
+	ProductLoginRateLimit   rest.Middleware
+	AdminLoginRateLimit     rest.Middleware
+	SyncRateLimit           rest.Middleware
+	RefreshTokenRateLimit   rest.Middleware
+	GrpcLoginLimiter        *limit.PeriodLimit
+	GrpcRefreshLimiter      *limit.PeriodLimit
+	GrpcVerifyLimiter       *limit.PeriodLimit
+	GrpcSyncLimiter         *limit.PeriodLimit
 	GrpcGetUserPermsLimiter *limit.PeriodLimit
-	UsernameLoginLimit    *limit.PeriodLimit
-	TokenOpLimiter        *limit.PeriodLimit
-	UserDetailsLoader     *loaders.UserDetailsLoader
-	Redis                 *redis.Redis
-	MinioClient           *minio.Client
+	UsernameLoginLimit      *limit.PeriodLimit
+	TokenOpLimiter          *limit.PeriodLimit
+	UserDetailsLoader       *loaders.UserDetailsLoader
+	Redis                   *redis.Redis
+	MinioClient             *minio.Client
 	*model.Models
 }
 
@@ -72,22 +72,22 @@ func NewServiceContext(c config.Config) *ServiceContext {
 	}
 
 	return &ServiceContext{
-		Config:                c,
-		JwtAuth:               middleware.NewJwtAuthMiddleware(c.Auth.AccessSecret, udLoader).Handle,
-		ProductLoginRateLimit: productLoginRL.Handle,
-		AdminLoginRateLimit:   adminLoginRL.Handle,
-		SyncRateLimit:         syncRlMiddleware.Handle,
-		RefreshTokenRateLimit: refreshTokenRL.Handle,
-		GrpcLoginLimiter:      grpcLimiter,
-		GrpcRefreshLimiter:    grpcRefreshLimiter,
-		GrpcVerifyLimiter:     grpcVerifyLimiter,
-		GrpcSyncLimiter:       grpcSyncLimiter,
+		Config:                  c,
+		JwtAuth:                 middleware.NewJwtAuthMiddleware(c.Auth.AccessSecret, udLoader).Handle,
+		ProductLoginRateLimit:   productLoginRL.Handle,
+		AdminLoginRateLimit:     adminLoginRL.Handle,
+		SyncRateLimit:           syncRlMiddleware.Handle,
+		RefreshTokenRateLimit:   refreshTokenRL.Handle,
+		GrpcLoginLimiter:        grpcLimiter,
+		GrpcRefreshLimiter:      grpcRefreshLimiter,
+		GrpcVerifyLimiter:       grpcVerifyLimiter,
+		GrpcSyncLimiter:         grpcSyncLimiter,
 		GrpcGetUserPermsLimiter: grpcGetUserPermsLimiter,
-		UsernameLoginLimit:    usernameLimiter,
-		TokenOpLimiter:        tokenOpLimiter,
-		UserDetailsLoader:     udLoader,
-		Redis:                 rds,
-		MinioClient:           minioClient,
-		Models:                models,
+		UsernameLoginLimit:      usernameLimiter,
+		TokenOpLimiter:          tokenOpLimiter,
+		UserDetailsLoader:       udLoader,
+		Redis:                   rds,
+		MinioClient:             minioClient,
+		Models:                  models,
 	}
 }