Skip to content

Commit ded0402

Browse files
committed
refactor: optimize project structure
1 parent d8c5eaa commit ded0402

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+105
-104
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ Fork code!
66
Create your own branch: git checkout -b feat/xxxx
77
Submit your changes: git commit -am 'feat(function): add xxxxx'
88
Push your branch: git push origin feat/xxxx
9-
submitpull request
9+
submit pull request

api/internal/logic/captcha/get_captcha_logic.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ import (
77
"github.com/suyuan32/simple-admin-core/api/internal/config"
88
"github.com/suyuan32/simple-admin-core/api/internal/svc"
99
"github.com/suyuan32/simple-admin-core/api/internal/types"
10-
"github.com/suyuan32/simple-admin-core/api/internal/util"
10+
"github.com/suyuan32/simple-admin-core/pkg/utils"
1111

1212
"github.com/mojocn/base64Captcha"
1313
"github.com/zeromicro/go-zero/core/errorx"
1414
"github.com/zeromicro/go-zero/core/logx"
1515
"github.com/zeromicro/go-zero/core/stores/redis"
1616
)
1717

18-
var Store *util.RedisStore
18+
var Store *utils.RedisStore
1919
var driver *base64Captcha.DriverDigit
2020

2121
type GetCaptchaLogic struct {
@@ -52,5 +52,5 @@ func (l *GetCaptchaLogic) GetCaptcha() (resp *types.CaptchaInfo, err error) {
5252
func initStoreAndDriver(c config.Config, r *redis.Redis) {
5353
driver = base64Captcha.NewDriverDigit(c.Captcha.ImgHeight, c.Captcha.ImgWidth,
5454
c.Captcha.KeyLong, 0.7, 80)
55-
Store = util.NewRedisStore(r)
55+
Store = utils.NewRedisStore(r)
5656
}

api/internal/logic/user/login_logic.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/suyuan32/simple-admin-core/api/internal/logic/captcha"
99
"github.com/suyuan32/simple-admin-core/api/internal/svc"
1010
"github.com/suyuan32/simple-admin-core/api/internal/types"
11-
"github.com/suyuan32/simple-admin-core/common/msg"
11+
"github.com/suyuan32/simple-admin-core/pkg/msg/i18n"
1212
"github.com/suyuan32/simple-admin-core/rpc/types/core"
1313

1414
"github.com/golang-jwt/jwt/v4"
@@ -74,7 +74,7 @@ func (l *LoginLogic) Login(req *types.LoginReq) (resp *types.LoginResp, err erro
7474
}
7575
return resp, nil
7676
} else {
77-
return nil, errorx.NewApiError(http.StatusBadRequest, msg.WrongCaptcha)
77+
return nil, errorx.NewApiError(http.StatusBadRequest, i18n.WrongCaptcha)
7878
}
7979
}
8080

api/internal/logic/user/register_logic.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"github.com/suyuan32/simple-admin-core/api/internal/logic/captcha"
88
"github.com/suyuan32/simple-admin-core/api/internal/svc"
99
"github.com/suyuan32/simple-admin-core/api/internal/types"
10-
"github.com/suyuan32/simple-admin-core/common/msg"
10+
"github.com/suyuan32/simple-admin-core/pkg/msg/i18n"
1111
"github.com/suyuan32/simple-admin-core/rpc/types/core"
1212

1313
"github.com/zeromicro/go-zero/core/errorx"
@@ -46,6 +46,6 @@ func (l *RegisterLogic) Register(req *types.RegisterReq) (resp *types.SimpleMsg,
4646
}
4747
return resp, nil
4848
} else {
49-
return nil, errorx.NewApiError(http.StatusBadRequest, msg.WrongCaptcha)
49+
return nil, errorx.NewApiError(http.StatusBadRequest, i18n.WrongCaptcha)
5050
}
5151
}

api/internal/middleware/authority_middleware.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"fmt"
66
"net/http"
77

8-
"github.com/suyuan32/simple-admin-core/common/logmsg"
9-
"github.com/suyuan32/simple-admin-core/common/msg"
8+
"github.com/suyuan32/simple-admin-core/pkg/msg/i18n"
9+
"github.com/suyuan32/simple-admin-core/pkg/msg/logmsg"
1010

1111
"github.com/casbin/casbin/v2"
1212
"github.com/zeromicro/go-zero/core/errorx"
@@ -43,7 +43,7 @@ func (m *AuthorityMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
4343
return
4444
} else if roleStatus == "0" {
4545
logx.Errorw("role is on forbidden status", logx.Field("roleId", roleId))
46-
httpx.Error(w, errorx.NewApiError(http.StatusBadRequest, msg.RoleForbidden))
46+
httpx.Error(w, errorx.NewApiError(http.StatusBadRequest, i18n.RoleForbidden))
4747
return
4848
}
4949

api/internal/svc/service_context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package svc
33
import (
44
"github.com/suyuan32/simple-admin-core/api/internal/config"
55
"github.com/suyuan32/simple-admin-core/api/internal/middleware"
6-
"github.com/suyuan32/simple-admin-core/common/logmsg"
6+
"github.com/suyuan32/simple-admin-core/pkg/msg/logmsg"
77
"github.com/suyuan32/simple-admin-core/rpc/coreclient"
88

99
"github.com/casbin/casbin/v2"

job/internal/svc/service_context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"github.com/zeromicro/go-zero/core/logx"
55
"gorm.io/gorm"
66

7-
"github.com/suyuan32/simple-admin-core/common/logmsg"
87
"github.com/suyuan32/simple-admin-core/job/internal/config"
8+
"github.com/suyuan32/simple-admin-core/pkg/msg/logmsg"
99
)
1010

1111
type ServiceContext struct {

common/msg/msg.go renamed to pkg/msg/i18n/msg.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package msg
1+
package i18n
22

33
const (
44
// user service messages
File renamed without changes.

api/internal/util/captcha.go renamed to pkg/utils/captcha.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package util
1+
package utils
22

33
import (
44
"context"

rpc/internal/util/encrypt.go renamed to pkg/utils/encrypt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package util
1+
package utils
22

33
import (
44
"golang.org/x/crypto/bcrypt"

rpc/internal/util/encrypt_test.go renamed to pkg/utils/encrypt_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
package util
1+
package utils
22

33
import (
4-
"github.com/stretchr/testify/assert"
54
"testing"
5+
6+
"github.com/stretchr/testify/assert"
67
)
78

89
func TestEncrypt(t *testing.T) {

rpc/internal/logic/block_user_all_token_logic.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"google.golang.org/grpc/status"
1111
"gorm.io/gorm"
1212

13-
"github.com/suyuan32/simple-admin-core/common/logmsg"
13+
"github.com/suyuan32/simple-admin-core/pkg/msg/logmsg"
1414
"github.com/suyuan32/simple-admin-core/rpc/internal/model"
1515
"github.com/suyuan32/simple-admin-core/rpc/internal/svc"
1616
"github.com/suyuan32/simple-admin-core/rpc/types/core"

rpc/internal/logic/change_password_logic.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import (
66

77
"gorm.io/gorm"
88

9-
"github.com/suyuan32/simple-admin-core/common/logmsg"
10-
"github.com/suyuan32/simple-admin-core/common/msg"
9+
"github.com/suyuan32/simple-admin-core/pkg/msg/i18n"
10+
"github.com/suyuan32/simple-admin-core/pkg/msg/logmsg"
11+
"github.com/suyuan32/simple-admin-core/pkg/utils"
1112
"github.com/suyuan32/simple-admin-core/rpc/internal/model"
1213
"github.com/suyuan32/simple-admin-core/rpc/internal/svc"
13-
"github.com/suyuan32/simple-admin-core/rpc/internal/util"
1414
"github.com/suyuan32/simple-admin-core/rpc/types/core"
1515

1616
"github.com/zeromicro/go-zero/core/errorx"
@@ -46,8 +46,8 @@ func (l *ChangePasswordLogic) ChangePassword(in *core.ChangePasswordReq) (*core.
4646
return nil, status.Error(codes.Internal, errorx.DatabaseError)
4747
}
4848

49-
if ok := util.BcryptCheck(in.OldPassword, target.Password); ok {
50-
target.Password = util.BcryptEncrypt(in.NewPassword)
49+
if ok := utils.BcryptCheck(in.OldPassword, target.Password); ok {
50+
target.Password = utils.BcryptEncrypt(in.NewPassword)
5151
result = l.svcCtx.DB.Updates(&target)
5252
if result.Error != nil {
5353
logx.Errorw(logmsg.DatabaseError, logx.Field("detail", result.Error.Error()))
@@ -58,7 +58,7 @@ func (l *ChangePasswordLogic) ChangePassword(in *core.ChangePasswordReq) (*core.
5858
}
5959
} else {
6060
logx.Errorw("old password is wrong", logx.Field("UUID", in.Uuid))
61-
return nil, status.Error(codes.InvalidArgument, msg.WrongPassword)
61+
return nil, status.Error(codes.InvalidArgument, i18n.WrongPassword)
6262
}
6363
logx.Infow("change password successful", logx.Field("UUID", in.Uuid))
6464
return &core.BaseResp{Msg: errorx.UpdateSuccess}, nil

rpc/internal/logic/create_or_update_api_logic.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"errors"
66
"time"
77

8-
"github.com/suyuan32/simple-admin-core/common/logmsg"
9-
"github.com/suyuan32/simple-admin-core/common/msg"
8+
"github.com/suyuan32/simple-admin-core/pkg/msg/i18n"
9+
"github.com/suyuan32/simple-admin-core/pkg/msg/logmsg"
1010
"github.com/suyuan32/simple-admin-core/rpc/internal/model"
1111
"github.com/suyuan32/simple-admin-core/rpc/internal/svc"
1212
"github.com/suyuan32/simple-admin-core/rpc/types/core"
@@ -50,8 +50,8 @@ func (l *CreateOrUpdateApiLogic) CreateOrUpdateApi(in *core.ApiInfo) (*core.Base
5050
}
5151

5252
if result.RowsAffected == 0 {
53-
logx.Errorw(msg.ApiAlreadyExists, logx.Field("detail", data))
54-
return nil, status.Error(codes.InvalidArgument, msg.ApiAlreadyExists)
53+
logx.Errorw(i18n.ApiAlreadyExists, logx.Field("detail", data))
54+
return nil, status.Error(codes.InvalidArgument, i18n.ApiAlreadyExists)
5555
}
5656

5757
logx.Infow(errorx.CreateSuccess, logx.Field("path", in.Path), logx.Field("desc", in.Description),

rpc/internal/logic/create_or_update_dictionary_detail_logic.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
"google.golang.org/grpc/status"
1111
"gorm.io/gorm"
1212

13-
"github.com/suyuan32/simple-admin-core/common/logmsg"
14-
"github.com/suyuan32/simple-admin-core/common/msg"
13+
"github.com/suyuan32/simple-admin-core/pkg/msg/i18n"
14+
"github.com/suyuan32/simple-admin-core/pkg/msg/logmsg"
1515
"github.com/suyuan32/simple-admin-core/rpc/internal/model"
1616
"github.com/suyuan32/simple-admin-core/rpc/internal/svc"
1717
"github.com/suyuan32/simple-admin-core/rpc/types/core"
@@ -36,8 +36,8 @@ func (l *CreateOrUpdateDictionaryDetailLogic) CreateOrUpdateDictionaryDetail(in
3636
check := l.svcCtx.DB.Where("id = ?", in.ParentId).First(&parent)
3737

3838
if errors.Is(check.Error, gorm.ErrRecordNotFound) {
39-
logx.Errorw(msg.ParentNotExist, logx.Field("detail", in))
40-
return nil, status.Error(codes.InvalidArgument, msg.ParentNotExist)
39+
logx.Errorw(i18n.ParentNotExist, logx.Field("detail", in))
40+
return nil, status.Error(codes.InvalidArgument, i18n.ParentNotExist)
4141
}
4242

4343
if check.Error != nil {

rpc/internal/logic/create_or_update_dictionary_logic.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
"google.golang.org/grpc/status"
1010
"gorm.io/gorm"
1111

12-
"github.com/suyuan32/simple-admin-core/common/logmsg"
13-
"github.com/suyuan32/simple-admin-core/common/msg"
12+
"github.com/suyuan32/simple-admin-core/pkg/msg/i18n"
13+
"github.com/suyuan32/simple-admin-core/pkg/msg/logmsg"
1414
"github.com/suyuan32/simple-admin-core/rpc/internal/model"
1515

1616
"github.com/suyuan32/simple-admin-core/rpc/internal/svc"
@@ -50,7 +50,7 @@ func (l *CreateOrUpdateDictionaryLogic) CreateOrUpdateDictionary(in *core.Dictio
5050
}
5151
if result.RowsAffected == 0 {
5252
logx.Errorw("dictionary already exists", logx.Field("detail", in))
53-
return nil, status.Error(codes.InvalidArgument, msg.DictionaryAlreadyExists)
53+
return nil, status.Error(codes.InvalidArgument, i18n.DictionaryAlreadyExists)
5454
}
5555

5656
return &core.BaseResp{Msg: errorx.CreateSuccess}, nil

rpc/internal/logic/create_or_update_menu_authority_logic.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"fmt"
66
"strings"
77

8-
"github.com/suyuan32/simple-admin-core/common/logmsg"
8+
"github.com/suyuan32/simple-admin-core/pkg/msg/logmsg"
99
"github.com/suyuan32/simple-admin-core/rpc/internal/svc"
1010
"github.com/suyuan32/simple-admin-core/rpc/types/core"
1111

rpc/internal/logic/create_or_update_menu_logic.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"errors"
66
"time"
77

8-
"github.com/suyuan32/simple-admin-core/common/logmsg"
9-
"github.com/suyuan32/simple-admin-core/common/msg"
8+
"github.com/suyuan32/simple-admin-core/pkg/msg/i18n"
9+
"github.com/suyuan32/simple-admin-core/pkg/msg/logmsg"
1010
"github.com/suyuan32/simple-admin-core/rpc/internal/model"
1111
"github.com/suyuan32/simple-admin-core/rpc/internal/svc"
1212
"github.com/suyuan32/simple-admin-core/rpc/types/core"
@@ -40,7 +40,7 @@ func (l *CreateOrUpdateMenuLogic) CreateOrUpdateMenu(in *core.CreateOrUpdateMenu
4040
result := l.svcCtx.DB.Where("id = ?", in.ParentId).First(&parent)
4141
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
4242
logx.Errorw("wrong parent ID", logx.Field("parentId", in.ParentId))
43-
return nil, status.Error(codes.InvalidArgument, msg.ParentNotExist)
43+
return nil, status.Error(codes.InvalidArgument, i18n.ParentNotExist)
4444
}
4545
if result.Error != nil {
4646
logx.Errorw(logmsg.DatabaseError, logx.Field("detail", result.Error.Error()))
@@ -87,7 +87,7 @@ func (l *CreateOrUpdateMenuLogic) CreateOrUpdateMenu(in *core.CreateOrUpdateMenu
8787
return nil, status.Error(codes.Internal, errorx.DatabaseError)
8888
}
8989
if result.RowsAffected == 0 {
90-
return nil, status.Error(codes.InvalidArgument, msg.MenuAlreadyExists)
90+
return nil, status.Error(codes.InvalidArgument, i18n.MenuAlreadyExists)
9191
}
9292

9393
logx.Infow("Create menu successfully", logx.Field("menuDetail", data))
@@ -96,7 +96,7 @@ func (l *CreateOrUpdateMenuLogic) CreateOrUpdateMenu(in *core.CreateOrUpdateMenu
9696
var origin *model.Menu
9797
result := l.svcCtx.DB.Where("id = ?", in.Id).First(&origin)
9898
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
99-
return nil, status.Error(codes.InvalidArgument, msg.MenuNotExists)
99+
return nil, status.Error(codes.InvalidArgument, i18n.MenuNotExists)
100100
}
101101

102102
if result.Error != nil {

rpc/internal/logic/create_or_update_menu_param_logic.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"google.golang.org/grpc/status"
1010
"gorm.io/gorm"
1111

12-
"github.com/suyuan32/simple-admin-core/common/logmsg"
12+
"github.com/suyuan32/simple-admin-core/pkg/msg/logmsg"
1313
"github.com/suyuan32/simple-admin-core/rpc/internal/model"
1414

1515
"github.com/suyuan32/simple-admin-core/rpc/internal/svc"

rpc/internal/logic/create_or_update_provider_logic.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
"google.golang.org/grpc/status"
1111
"gorm.io/gorm"
1212

13-
"github.com/suyuan32/simple-admin-core/common/logmsg"
14-
"github.com/suyuan32/simple-admin-core/common/msg"
13+
"github.com/suyuan32/simple-admin-core/pkg/msg/i18n"
14+
"github.com/suyuan32/simple-admin-core/pkg/msg/logmsg"
1515
"github.com/suyuan32/simple-admin-core/rpc/internal/model"
1616
"github.com/suyuan32/simple-admin-core/rpc/internal/svc"
1717
"github.com/suyuan32/simple-admin-core/rpc/types/core"
@@ -56,8 +56,8 @@ func (l *CreateOrUpdateProviderLogic) CreateOrUpdateProvider(in *core.ProviderIn
5656
}
5757

5858
if result.RowsAffected == 0 {
59-
logx.Errorw(msg.ApiAlreadyExists, logx.Field("detail", data))
60-
return nil, status.Error(codes.InvalidArgument, msg.ApiAlreadyExists)
59+
logx.Errorw(i18n.ApiAlreadyExists, logx.Field("detail", data))
60+
return nil, status.Error(codes.InvalidArgument, i18n.ApiAlreadyExists)
6161
}
6262

6363
logx.Infow(logmsg.CreateSuccess, logx.Field("detail", in))

rpc/internal/logic/create_or_update_role_logic.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
"strconv"
88
"time"
99

10-
"github.com/suyuan32/simple-admin-core/common/logmsg"
11-
"github.com/suyuan32/simple-admin-core/common/msg"
10+
"github.com/suyuan32/simple-admin-core/pkg/msg/i18n"
11+
"github.com/suyuan32/simple-admin-core/pkg/msg/logmsg"
1212
"github.com/suyuan32/simple-admin-core/rpc/internal/model"
1313
"github.com/suyuan32/simple-admin-core/rpc/internal/svc"
1414
"github.com/suyuan32/simple-admin-core/rpc/types/core"
@@ -53,7 +53,7 @@ func (l *CreateOrUpdateRoleLogic) CreateOrUpdateRole(in *core.RoleInfo) (*core.B
5353
}
5454
if result.RowsAffected == 0 {
5555
logx.Errorw("role value had been used", logx.Field("detail", data))
56-
return nil, status.Error(codes.InvalidArgument, msg.DuplicateRoleValue)
56+
return nil, status.Error(codes.InvalidArgument, i18n.DuplicateRoleValue)
5757
}
5858

5959
err := l.UpdateRoleInfoInRedis()

rpc/internal/logic/create_or_update_token_logic.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
"google.golang.org/grpc/status"
1111
"gorm.io/gorm"
1212

13-
"github.com/suyuan32/simple-admin-core/common/logmsg"
14-
"github.com/suyuan32/simple-admin-core/common/msg"
13+
"github.com/suyuan32/simple-admin-core/pkg/msg/i18n"
14+
"github.com/suyuan32/simple-admin-core/pkg/msg/logmsg"
1515
"github.com/suyuan32/simple-admin-core/rpc/internal/model"
1616
"github.com/suyuan32/simple-admin-core/rpc/internal/svc"
1717
"github.com/suyuan32/simple-admin-core/rpc/types/core"
@@ -50,7 +50,7 @@ func (l *CreateOrUpdateTokenLogic) CreateOrUpdateToken(in *core.TokenInfo) (*cor
5050
}
5151
if result.RowsAffected == 0 {
5252
logx.Errorw("Token already exists", logx.Field("detail", in))
53-
return nil, status.Error(codes.InvalidArgument, msg.DictionaryAlreadyExists)
53+
return nil, status.Error(codes.InvalidArgument, i18n.DictionaryAlreadyExists)
5454
}
5555

5656
return &core.BaseResp{Msg: errorx.CreateSuccess}, nil

0 commit comments

Comments
 (0)