Skip to content

Commit

Permalink
Merge pull request #45 from suyuan32/fix-reuse-pkg
Browse files Browse the repository at this point in the history
Fix reuse pkg
  • Loading branch information
suyuan32 authored Nov 18, 2022
2 parents 1a707a4 + 93b27fd commit 3e40a8d
Show file tree
Hide file tree
Showing 59 changed files with 301 additions and 362 deletions.
2 changes: 1 addition & 1 deletion api/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Schemes: http, https
// Host: localhost:9100
// BasePath: /
// Version: 0.1.2
// Version: 0.1.6
// Contact: [email protected]
// SecurityDefinitions:
// Token:
Expand Down
18 changes: 3 additions & 15 deletions api/desc/base.api
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ type SimpleMsg {
}

// The page request parameters | 列表请求参数
// swagger:model PageInfo
type PageInfo {
// Page number | 第几页
// Required: true
Expand All @@ -58,29 +57,19 @@ type PageInfo {
PageSize uint64 `json:"pageSize" validate:"number,max=100000"`
}

// The page response data model | 列表返回信息
// swagger:response PageList
type PageList {
// Total number | 数据总数
Total uint64 `json:"total"`

// Data | 数据
Data []string `json:"data"`
}

// Basic id request | 基础id参数请求
// Basic ID request | 基础ID参数请求
type IDReq {
// ID
// Required: true
Id uint64 `json:"id" validate:"number"`
}


// Basic id request | 基础id参数请求
// Basic ID request | 基础ID地址参数请求
type IDPathReq {
// ID
// Required: true
Id uint `path:"id"`
Id uint64 `path:"id"`
}

// Basic UUID request | 基础UUID参数请求
Expand All @@ -92,7 +81,6 @@ type UUIDReq {
}

// The base response data | 基础信息
// swagger:model BaseInfo
type BaseInfo {
// ID
Id uint64 `json:"id"`
Expand Down
2 changes: 1 addition & 1 deletion api/internal/logic/core/init_database_logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (l *InitDatabaseLogic) InitDatabase() (resp *types.BaseMsgResp, err error)
if initState, err := l.svcCtx.Redis.Get("database_init_state"); err == nil {
if initState == "1" {
return nil, errorx.NewCodeError(enum.InvalidArgument,
l.svcCtx.Trans.Trans(l.lang, "init.alreadyInit"))
l.svcCtx.Trans.Trans(l.lang, i18n.AlreadyInit))
}
} else {
return nil, errorx.NewCodeError(enum.Internal,
Expand Down
3 changes: 2 additions & 1 deletion api/internal/middleware/authority_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"net/http"

"github.com/suyuan32/simple-admin-core/pkg/i18n"
"github.com/suyuan32/simple-admin-core/pkg/msg/logmsg"

"github.com/casbin/casbin/v2"
Expand Down Expand Up @@ -63,7 +64,7 @@ func (m *AuthorityMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
result, err := m.Cbn.Enforce(sub, obj, act)
if err != nil {
logx.Errorw("casbin enforce error", logx.Field("detail", err.Error()))
httpx.Error(w, errorx.NewApiError(http.StatusInternalServerError, errorx.ApiRequestFailed))
httpx.Error(w, errorx.NewApiError(http.StatusInternalServerError, i18n.ApiRequestFailed))
return
}
if result {
Expand Down
4 changes: 2 additions & 2 deletions api/internal/svc/service_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func NewServiceContext(c config.Config) *ServiceContext {
}
logx.Info("initialize redis connection successfully")

// initialize database connection
cbn, err := c.CasbinConf.NewCasbin(c.DatabaseConf)
// initialize casbin connection
cbn, err := c.CasbinConf.NewCasbin(c.DatabaseConf.Type, c.DatabaseConf.GetDSN())
if err != nil {
logx.Errorw("Initialize casbin failed", logx.Field("detail", err.Error()))
return nil
Expand Down
15 changes: 3 additions & 12 deletions api/internal/types/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 3 additions & 15 deletions core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,7 @@ definitions:
type: object
x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types
IDPathReq:
description: Basic id request | 基础id参数请求
description: Basic ID request | 基础ID地址参数请求
properties:
Id:
description: ID
Expand All @@ -1135,7 +1135,7 @@ definitions:
type: object
x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types
IDReq:
description: Basic id request | 基础id参数请求
description: Basic ID request | 基础ID参数请求
properties:
id:
description: ID
Expand Down Expand Up @@ -2223,7 +2223,7 @@ info:
email: [email protected]
description: This is simple admin api doc
title: Simple Admin
version: 0.1.2
version: 0.1.6
paths:
/api:
delete:
Expand Down Expand Up @@ -3035,18 +3035,6 @@ paths:
produces:
- application/json
responses:
PageList:
description: The page response data model | 列表返回信息
headers:
data:
description: Data | 数据
items:
type: string
type: array
total:
description: Total number | 数据总数
format: uint64
type: integer
SimpleMsg:
description: The simplest message | 最简单的信息
headers:
Expand Down
8 changes: 4 additions & 4 deletions docs/simple-admin/en/docs/ent.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ func (l *UpdateRoleStatusLogic) UpdateRoleStatus(in *core.StatusCodeReq) (*core.
switch {
case ent.IsNotFound(err):
logx.Errorw(err.Error(), logx.Field("detail", in))
return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound)
return nil, statuserr.NewInvalidArgumentError(i18n.TargetNotFound)
default:
logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error()))
return nil, statuserr.NewInternalError(errorx.DatabaseError)
return nil, statuserr.NewInternalError(i18n.DatabaseError)
}
}

Expand All @@ -179,10 +179,10 @@ func (l *UpdateRoleStatusLogic) UpdateRoleStatus(in *core.StatusCodeReq) (*core.
err = l.svcCtx.Redis.Hset("roleData", fmt.Sprintf("%d_value", role.ID), role.Value)
err = l.svcCtx.Redis.Hset("roleData", fmt.Sprintf("%d_status", role.ID), strconv.Itoa(int(role.Status)))
if err != nil {
return nil, statuserr.NewInternalError(errorx.RedisError)
return nil, statuserr.NewInternalError(i18n.RedisError)
}

return &core.BaseResp{Msg: errorx.UpdateSuccess}, nil
return &core.BaseResp{Msg: i18n.UpdateSuccess}, nil
}

```
20 changes: 11 additions & 9 deletions docs/simple-admin/en/docs/file_manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,14 @@ RedisConf:

DatabaseConf:
Type: mysql
Path: 127.0.0.1
Host: 127.0.0.1
Port: 3306
Config: charset=utf8mb4&parseTime=True&loc=Local
DBName: simple_admin_file
Username:
Password:
MaxIdleConn: 10
DBName: simple_admin
Username: # set your username
Password: # set your password
MaxOpenConn: 100
LogMode: error
LogZap: false
SSLMode: false
CacheTime: 5

UploadConf:
MaxImageSize: 33554432 # 32 mb the maximum size of image
Expand All @@ -51,12 +49,16 @@ UploadConf:
MaxOtherSize: 10485760 # 10 mb the maximum size of other type
PrivateStorePath: /home/ryan/www/private # private path
PublicStorePath: /home/ryan/www/public # public path for every one access e.g. nginx path

CoreRpc:
Target: k8s://default/core-rpc-svc:9101 # core rpc address, use endpoint in local | core 服务RPC地址,本地测试使用直连
```
> You should use nginx to set PublicStorePath as static path for front end.
> Make sure AccessSecret is the same as simple-admin-core' api set
> Make sure AccessSecret is the same as simple-admin-core's api set
> The configuration is similar as core
> Run code the same as core
> Init database in http://localhost:3100/init
### K8s Deployment
> It is similar with core api.
Expand Down
12 changes: 6 additions & 6 deletions docs/simple-admin/en/docs/global_vars.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ func (l *CreateOrUpdateApiLogic) CreateOrUpdateApi(in *core.ApiInfo) (*core.Base
return nil, statuserr.NewInvalidArgumentError(i18n.ApiAlreadyExists)
default:
logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error()))
return nil, statuserr.NewInternalError(errorx.DatabaseError)
return nil, statuserr.NewInternalError(i18n.DatabaseError)
}
}

return &core.BaseResp{Msg: errorx.CreateSuccess}, nil
return &core.BaseResp{Msg: i18n.CreateSuccess}, nil
} else {
err := l.svcCtx.DB.API.UpdateOneID(in.Id).
SetPath(in.Path).
Expand All @@ -111,17 +111,17 @@ func (l *CreateOrUpdateApiLogic) CreateOrUpdateApi(in *core.ApiInfo) (*core.Base
switch {
case ent.IsNotFound(err):
logx.Errorw(err.Error(), logx.Field("detail", in))
return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound)
return nil, statuserr.NewInvalidArgumentError(i18n.TargetNotFound)
case ent.IsConstraintError(err):
logx.Errorw(err.Error(), logx.Field("detail", in))
return nil, statuserr.NewInvalidArgumentError(errorx.UpdateFailed)
return nil, statuserr.NewInvalidArgumentError(i18n.UpdateFailed)
default:
logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error()))
return nil, statuserr.NewInternalError(errorx.DatabaseError)
return nil, statuserr.NewInternalError(i18n.DatabaseError)
}
}

return &core.BaseResp{Msg: errorx.UpdateSuccess}, nil
return &core.BaseResp{Msg: i18n.UpdateSuccess}, nil
}
}

Expand Down
8 changes: 4 additions & 4 deletions docs/simple-admin/zh-cn/docs/ent.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ func (l *UpdateRoleStatusLogic) UpdateRoleStatus(in *core.StatusCodeReq) (*core.
switch {
case ent.IsNotFound(err):
logx.Errorw(err.Error(), logx.Field("detail", in))
return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound)
return nil, statuserr.NewInvalidArgumentError(i18n.TargetNotFound)
default:
logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error()))
return nil, statuserr.NewInternalError(errorx.DatabaseError)
return nil, statuserr.NewInternalError(i18n.DatabaseError)
}
}

Expand All @@ -179,10 +179,10 @@ func (l *UpdateRoleStatusLogic) UpdateRoleStatus(in *core.StatusCodeReq) (*core.
err = l.svcCtx.Redis.Hset("roleData", fmt.Sprintf("%d_value", role.ID), role.Value)
err = l.svcCtx.Redis.Hset("roleData", fmt.Sprintf("%d_status", role.ID), strconv.Itoa(int(role.Status)))
if err != nil {
return nil, statuserr.NewInternalError(errorx.RedisError)
return nil, statuserr.NewInternalError(i18n.RedisError)
}

return &core.BaseResp{Msg: errorx.UpdateSuccess}, nil
return &core.BaseResp{Msg: i18n.UpdateSuccess}, nil
}

```
24 changes: 13 additions & 11 deletions docs/simple-admin/zh-cn/docs/file_manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,14 @@ RedisConf:

DatabaseConf:
Type: mysql
Path: 127.0.0.1
Host: 127.0.0.1
Port: 3306
Config: charset=utf8mb4&parseTime=True&loc=Local
DBName: simple_admin_file
Username:
Password:
MaxIdleConn: 10
DBName: simple_admin
Username: # set your username
Password: # set your password
MaxOpenConn: 100
LogMode: error
LogZap: false
SSLMode: false
CacheTime: 5

UploadConf:
MaxImageSize: 33554432 # 32 mb 最大图片大小
Expand All @@ -52,12 +50,16 @@ UploadConf:
MaxOtherSize: 10485760 # 10 mb 最大其他类型大小
PrivateStorePath: /home/ryan/www/private # private 私有文件路径
PublicStorePath: /home/ryan/www/public # public path for every one access e.g. nginx path 公开文件路径

CoreRpc:
Target: k8s://default/core-rpc-svc:9101 # core rpc address, use endpoint in local | core 服务RPC地址,本地测试使用直连
```
> 你可以使用nginx 将 PublicStorePath 转发为静态地址方便前端调用
> 确保 AccessSecret 和 simple-admin-core的api配置文件内一致 \
配置方式参考core \
运行方式同理
> 确保 AccessSecret 和 simple-admin-core的api配置文件内一致
> 配置方式参考core
> 运行方式同理
> 初始化数据库 http://localhost:3100/init
### K8s 部署
> 和 core api 相似
Expand Down
12 changes: 6 additions & 6 deletions docs/simple-admin/zh-cn/docs/global_vars.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ func (l *CreateOrUpdateApiLogic) CreateOrUpdateApi(in *core.ApiInfo) (*core.Base
return nil, statuserr.NewInvalidArgumentError(i18n.ApiAlreadyExists)
default:
logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error()))
return nil, statuserr.NewInternalError(errorx.DatabaseError)
return nil, statuserr.NewInternalError(i18n.DatabaseError)
}
}

return &core.BaseResp{Msg: errorx.CreateSuccess}, nil
return &core.BaseResp{Msg: i18n.CreateSuccess}, nil
} else {
err := l.svcCtx.DB.API.UpdateOneID(in.Id).
SetPath(in.Path).
Expand All @@ -110,17 +110,17 @@ func (l *CreateOrUpdateApiLogic) CreateOrUpdateApi(in *core.ApiInfo) (*core.Base
switch {
case ent.IsNotFound(err):
logx.Errorw(err.Error(), logx.Field("detail", in))
return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound)
return nil, statuserr.NewInvalidArgumentError(i18n.TargetNotFound)
case ent.IsConstraintError(err):
logx.Errorw(err.Error(), logx.Field("detail", in))
return nil, statuserr.NewInvalidArgumentError(errorx.UpdateFailed)
return nil, statuserr.NewInvalidArgumentError(i18n.UpdateFailed)
default:
logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error()))
return nil, statuserr.NewInternalError(errorx.DatabaseError)
return nil, statuserr.NewInternalError(i18n.DatabaseError)
}
}

return &core.BaseResp{Msg: errorx.UpdateSuccess}, nil
return &core.BaseResp{Msg: i18n.UpdateSuccess}, nil
}
}

Expand Down
Loading

0 comments on commit 3e40a8d

Please sign in to comment.