feature(安装): 安装时新增选择语言包

- 安装时新增选择语言包
- 优化代码并删除无用的代码
This commit is contained in:
新亮
2021-06-26 12:06:20 +08:00
parent 44ca2698cd
commit eba8929b4d
60 changed files with 706 additions and 488 deletions
+57 -123
View File
@@ -1,5 +1,7 @@
package code
import "github.com/xinliangnote/go-gin-api/configs"
// Failure 错误时返回结构
type Failure struct {
Code int `json:"code"` // 业务码
@@ -7,137 +9,69 @@ type Failure struct {
}
const (
// 服务级错误码
ServerError = 10101
TooManyRequests = 10102
ParamBindError = 10103
AuthorizationError = 10104
CallHTTPError = 10105
ResubmitError = 10106
ResubmitMsg = 10107
HashIdsDecodeError = 10108
SignatureError = 10109
RBACError = 10110
UrlSignError = 10105
CacheSetError = 10106
CacheGetError = 10107
CacheDelError = 10108
CacheNotExist = 10109
ResubmitError = 10110
HashIdsEncodeError = 10111
HashIdsDecodeError = 10112
RBACError = 10113
RedisConnectError = 10114
MySQLConnectError = 10115
WriteConfigError = 10116
SendEmailError = 10117
MySQLExecError = 10118
GoVersionError = 10119
// 业务模块级错误码
// 用户模块
IllegalUserName = 20101
UserCreateError = 20102
UserUpdateError = 20103
UserSearchError = 20104
AuthorizedCreateError = 20101
AuthorizedListError = 20102
AuthorizedDeleteError = 20103
AuthorizedUpdateError = 20104
AuthorizedDetailError = 20105
AuthorizedCreateAPIError = 20106
AuthorizedListAPIError = 20107
AuthorizedDeleteAPIError = 20108
// 授权调用方
AuthorizedCreateError = 20201
AuthorizedListError = 20202
AuthorizedDeleteError = 20203
AuthorizedUpdateError = 20204
AuthorizedDetailError = 20205
AuthorizedCreateAPIError = 20206
AuthorizedListAPIError = 20207
AuthorizedDeleteAPIError = 20208
AdminCreateError = 20201
AdminListError = 20202
AdminDeleteError = 20203
AdminUpdateError = 20204
AdminResetPasswordError = 20205
AdminLoginError = 20206
AdminLogOutError = 20207
AdminModifyPasswordError = 20208
AdminModifyPersonalInfoError = 20209
AdminMenuListError = 20210
AdminMenuCreateError = 20211
AdminOfflineError = 20212
AdminDetailError = 20213
// 管理员
AdminCreateError = 20301
AdminListError = 20302
AdminDeleteError = 20303
AdminUpdateError = 20304
AdminResetPasswordError = 20305
AdminLoginError = 20306
AdminLogOutError = 20307
AdminModifyPasswordError = 20308
AdminModifyPersonalInfoError = 20309
AdminMenuListError = 20310
AdminMenuCreateError = 20311
AdminOfflineError = 20312
AdminDetailError = 20313
// 配置
ConfigEmailError = 20401
ConfigSaveError = 20402
ConfigRedisConnectError = 20403
ConfigMySQLConnectError = 20404
ConfigMySQLInstallError = 20405
ConfigGoVersionError = 20406
// 实用工具箱
SearchRedisError = 20501
ClearRedisError = 20502
SearchRedisEmpty = 20503
SearchMySQLError = 20504
// 菜单栏
MenuCreateError = 20601
MenuUpdateError = 20602
MenuListError = 20603
MenuDeleteError = 20604
MenuDetailError = 20605
MenuCreateActionError = 20606
MenuListActionError = 20607
MenuDeleteActionError = 20608
MenuCreateError = 20301
MenuUpdateError = 20302
MenuListError = 20303
MenuDeleteError = 20304
MenuDetailError = 20305
MenuCreateActionError = 20306
MenuListActionError = 20307
MenuDeleteActionError = 20308
)
var codeText = map[int]string{
ServerError: "Internal Server Error",
TooManyRequests: "Too Many Requests",
ParamBindError: "参数信息有误",
AuthorizationError: "签名信息有误",
CallHTTPError: "调用第三方 HTTP 接口失败",
ResubmitError: "Resubmit Error",
ResubmitMsg: "请勿重复提交",
HashIdsDecodeError: "ID 参数有误",
SignatureError: "Signature Error",
RBACError: "暂无权限,请联系管理开通权限",
IllegalUserName: "非法用户名",
UserCreateError: "创建用户失败",
UserUpdateError: "更新用户失败",
UserSearchError: "查询用户失败",
AuthorizedCreateError: "创建调用方失败",
AuthorizedListError: "获取调用方列表页失败",
AuthorizedDeleteError: "删除调用方失败",
AuthorizedUpdateError: "更新调用方失败",
AuthorizedDetailError: "获取调用方详情失败",
AuthorizedCreateAPIError: "创建调用方API地址失败",
AuthorizedListAPIError: "获取调用方API地址列表失败",
AuthorizedDeleteAPIError: "删除调用方API地址失败",
AdminCreateError: "创建管理员失败",
AdminListError: "获取管理员列表页失败",
AdminDeleteError: "删除管理员失败",
AdminUpdateError: "更新管理员失败",
AdminResetPasswordError: "重置密码失败",
AdminLoginError: "登录失败",
AdminLogOutError: "退出失败",
AdminModifyPasswordError: "修改密码失败",
AdminModifyPersonalInfoError: "修改个人信息失败",
AdminMenuListError: "获取管理员菜单授权列表失败",
AdminMenuCreateError: "管理员菜单授权失败",
AdminOfflineError: "下线管理员失败",
AdminDetailError: "获取个人信息失败",
ConfigEmailError: "修改邮箱配置失败",
ConfigSaveError: "写入配置文件失败",
ConfigRedisConnectError: "Redis 连接失败",
ConfigMySQLConnectError: "MySQL 连接失败",
ConfigMySQLInstallError: "MySQL 初始化数据失败",
ConfigGoVersionError: "Go Version 不满足要求",
SearchRedisError: "查询 Redis Key 失败",
ClearRedisError: "清空 Redis Key 失败",
SearchRedisEmpty: "查询的 Redis Key 不存在",
SearchMySQLError: "查询 MySQL 失败",
MenuCreateError: "创建菜单失败",
MenuUpdateError: "更新菜单失败",
MenuDeleteError: "删除菜单失败",
MenuListError: "获取菜单列表页失败",
MenuDetailError: "获取菜单详情失败",
MenuCreateActionError: "创建菜单栏功能权限失败",
MenuListActionError: "获取菜单栏功能权限列表失败",
MenuDeleteActionError: "删除菜单栏功能权限失败",
}
func Text(code int) string {
return codeText[code]
lang := configs.Get().Language.Local
if lang == configs.ZhCN {
return zhCNText[code]
}
if lang == configs.EnUS {
return enUSText[code]
}
return zhCNText[code]
}
+55
View File
@@ -0,0 +1,55 @@
package code
var enUSText = map[int]string{
ServerError: "Internal server error",
TooManyRequests: "Too many requests",
ParamBindError: "Parameter error",
AuthorizationError: "Authorization error",
UrlSignError: "URL signature error",
CacheSetError: "Failed to set cache",
CacheGetError: "Failed to get cache",
CacheDelError: "Failed to del cache",
CacheNotExist: "Cache does not exist",
ResubmitError: "Please do not submit repeatedly",
HashIdsEncodeError: "HashID encryption failed",
HashIdsDecodeError: "HashID decryption failed",
RBACError: "No access",
RedisConnectError: "Failed to connection Redis",
MySQLConnectError: "Failed to connection MySQL",
WriteConfigError: "Failed to write configuration file",
SendEmailError: "Failed to send mail",
MySQLExecError: "SQL execution failed",
GoVersionError: "Go Version mismatch",
AuthorizedCreateError: "Failed to create caller",
AuthorizedListError: "Failed to get caller list",
AuthorizedDeleteError: "Failed to delete caller",
AuthorizedUpdateError: "Failed to update caller",
AuthorizedDetailError: "Failed to get caller details",
AuthorizedCreateAPIError: "Failed to create caller API address",
AuthorizedListAPIError: "Failed to get caller API address list",
AuthorizedDeleteAPIError: "Failed to delete caller API address",
AdminCreateError: "Failed to create administrator",
AdminListError: "Failed to get administrator list",
AdminDeleteError: "Failed to delete administrator",
AdminUpdateError: "Failed to update administrator",
AdminResetPasswordError: "Reset password failed",
AdminLoginError: "Login failed",
AdminLogOutError: "Exit failed",
AdminModifyPasswordError: "Failed to modify password",
AdminModifyPersonalInfoError: "Failed to modify personal information",
AdminMenuListError: "Failed to get administrator menu authorization list",
AdminMenuCreateError: "Administrator menu authorization failed",
AdminOfflineError: "Offline administrator failed",
AdminDetailError: "Failed to get personal information",
MenuCreateError: "Failed to create menu",
MenuUpdateError: "Failed to update menu",
MenuDeleteError: "Failed to delete menu",
MenuListError: "Failed to get menu list",
MenuDetailError: "Failed to get menu details",
MenuCreateActionError: "Failed to create menu action",
MenuListActionError: "Failed to get menu action list",
MenuDeleteActionError: "Failed to delete menu action",
}
+55
View File
@@ -0,0 +1,55 @@
package code
var zhCNText = map[int]string{
ServerError: "内部服务器错误",
TooManyRequests: "请求过多",
ParamBindError: "参数信息错误",
AuthorizationError: "签名信息错误",
UrlSignError: "参数签名错误",
CacheSetError: "设置缓存失败",
CacheGetError: "获取缓存失败",
CacheDelError: "删除缓存失败",
CacheNotExist: "缓存不存在",
ResubmitError: "请勿重复提交",
HashIdsEncodeError: "HashID 加密失败",
HashIdsDecodeError: "HashID 解密失败",
RBACError: "暂无访问权限",
RedisConnectError: "Redis 连接失败",
MySQLConnectError: "MySQL 连接失败",
WriteConfigError: "写入配置文件失败",
SendEmailError: "发送邮件失败",
MySQLExecError: "SQL 执行失败",
GoVersionError: "Go 版本不满足要求",
AuthorizedCreateError: "创建调用方失败",
AuthorizedListError: "获取调用方列表失败",
AuthorizedDeleteError: "删除调用方失败",
AuthorizedUpdateError: "更新调用方失败",
AuthorizedDetailError: "获取调用方详情失败",
AuthorizedCreateAPIError: "创建调用方 API 地址失败",
AuthorizedListAPIError: "获取调用方 API 地址列表失败",
AuthorizedDeleteAPIError: "删除调用方 API 地址失败",
AdminCreateError: "创建管理员失败",
AdminListError: "获取管理员列表失败",
AdminDeleteError: "删除管理员失败",
AdminUpdateError: "更新管理员失败",
AdminResetPasswordError: "重置密码失败",
AdminLoginError: "登录失败",
AdminLogOutError: "退出失败",
AdminModifyPasswordError: "修改密码失败",
AdminModifyPersonalInfoError: "修改个人信息失败",
AdminMenuListError: "获取管理员菜单授权列表失败",
AdminMenuCreateError: "管理员菜单授权失败",
AdminOfflineError: "下线管理员失败",
AdminDetailError: "获取个人信息失败",
MenuCreateError: "创建菜单失败",
MenuUpdateError: "更新菜单失败",
MenuDeleteError: "删除菜单失败",
MenuListError: "获取菜单列表失败",
MenuDetailError: "获取菜单详情失败",
MenuCreateActionError: "创建菜单栏功能权限失败",
MenuListActionError: "获取菜单栏功能权限列表失败",
MenuDeleteActionError: "删除菜单栏功能权限失败",
}
@@ -12,7 +12,6 @@ import (
"github.com/xinliangnote/go-gin-api/pkg/time_parse"
"github.com/spf13/cast"
"go.uber.org/zap"
)
type listRequest struct {
@@ -117,7 +116,12 @@ func (h *handler) List() core.HandlerFunc {
for k, v := range resListData {
hashId, err := h.hashids.HashidsEncode([]int{cast.ToInt(v.Id)})
if err != nil {
h.logger.Info("hashids err", zap.Error(err))
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.HashIdsEncodeError,
code.Text(code.HashIdsEncodeError)).WithErr(err),
)
return
}
isOnline := -1
@@ -10,7 +10,6 @@ import (
"github.com/xinliangnote/go-gin-api/pkg/time_parse"
"github.com/spf13/cast"
"go.uber.org/zap"
)
type listRequest struct {
@@ -117,7 +116,12 @@ func (h *handler) List() core.HandlerFunc {
for k, v := range resListData {
hashId, err := h.hashids.HashidsEncode([]int{cast.ToInt(v.Id)})
if err != nil {
h.logger.Info("hashids err", zap.Error(err))
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.HashIdsEncodeError,
code.Text(code.HashIdsEncodeError)).WithErr(err),
)
return
}
data := listData{
@@ -9,7 +9,6 @@ import (
"github.com/xinliangnote/go-gin-api/pkg/errno"
"github.com/spf13/cast"
"go.uber.org/zap"
)
type listAPIRequest struct {
@@ -94,7 +93,12 @@ func (h *handler) ListAPI() core.HandlerFunc {
for k, v := range resListData {
hashId, err := h.hashids.HashidsEncode([]int{cast.ToInt(v.Id)})
if err != nil {
h.logger.Info("hashids err", zap.Error(err))
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.HashIdsEncodeError,
code.Text(code.HashIdsEncodeError)).WithErr(err),
)
return
}
data := listAPIData{
@@ -66,8 +66,8 @@ func (h *handler) Email() core.HandlerFunc {
if err := mail.Send(options); err != nil {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.ConfigEmailError,
"Mail Send error: "+err.Error()).WithErr(err),
code.SendEmailError,
code.Text(code.SendEmailError)+err.Error()).WithErr(err),
)
return
}
@@ -86,8 +86,8 @@ func (h *handler) Email() core.HandlerFunc {
if err != nil {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.ConfigEmailError,
code.Text(code.ConfigEmailError)).WithErr(err),
code.WriteConfigError,
code.Text(code.WriteConfigError)).WithErr(err),
)
return
}
@@ -9,7 +9,6 @@ import (
"github.com/xinliangnote/go-gin-api/pkg/errno"
"github.com/spf13/cast"
"go.uber.org/zap"
)
type listData struct {
@@ -54,7 +53,12 @@ func (h *handler) List() core.HandlerFunc {
for k, v := range resListData {
hashId, err := h.hashids.HashidsEncode([]int{cast.ToInt(v.Id)})
if err != nil {
h.logger.Info("hashids err", zap.Error(err))
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.HashIdsEncodeError,
code.Text(code.HashIdsEncodeError)).WithErr(err),
)
return
}
data := listData{
@@ -9,7 +9,6 @@ import (
"github.com/xinliangnote/go-gin-api/pkg/errno"
"github.com/spf13/cast"
"go.uber.org/zap"
)
type listActionRequest struct {
@@ -96,7 +95,12 @@ func (h *handler) ListAction() core.HandlerFunc {
for k, v := range resListData {
hashId, err := h.hashids.HashidsEncode([]int{cast.ToInt(v.Id)})
if err != nil {
h.logger.Info("hashids err", zap.Error(err))
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.HashIdsEncodeError,
code.Text(code.HashIdsEncodeError)).WithErr(err),
)
return
}
data := listActionData{
@@ -43,8 +43,8 @@ func (h *handler) ClearCache() core.HandlerFunc {
if b := h.cache.Exists(req.RedisKey); b != true {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.SearchRedisEmpty,
code.Text(code.SearchRedisEmpty)),
code.CacheNotExist,
code.Text(code.CacheNotExist)),
)
return
}
@@ -53,8 +53,8 @@ func (h *handler) ClearCache() core.HandlerFunc {
if b != true {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.ClearRedisError,
code.Text(code.ClearRedisError)),
code.CacheDelError,
code.Text(code.CacheDelError)),
)
return
}
@@ -45,8 +45,8 @@ func (h *handler) HashIdsEncode() core.HandlerFunc {
if err != nil {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.HashIdsDecodeError,
code.Text(code.HashIdsDecodeError)).WithErr(err),
code.HashIdsEncodeError,
code.Text(code.HashIdsEncodeError)).WithErr(err),
)
return
}
@@ -44,8 +44,8 @@ func (h *handler) SearchCache() core.HandlerFunc {
if b := h.cache.Exists(req.RedisKey); b != true {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.SearchRedisEmpty,
code.Text(code.SearchRedisEmpty)),
code.CacheNotExist,
code.Text(code.CacheNotExist)),
)
return
}
@@ -54,8 +54,8 @@ func (h *handler) SearchCache() core.HandlerFunc {
if err != nil {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.SearchRedisError,
code.Text(code.SearchRedisError)).WithErr(err),
code.CacheGetError,
code.Text(code.CacheGetError)).WithErr(err),
)
return
}
@@ -64,8 +64,8 @@ func (h *handler) SearchCache() core.HandlerFunc {
if err != nil {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.SearchRedisError,
code.Text(code.SearchRedisError)).WithErr(err),
code.CacheGetError,
code.Text(code.CacheGetError)).WithErr(err),
)
return
}
@@ -97,7 +97,7 @@ func (h *handler) SearchMySQL() core.HandlerFunc {
if sql == "" {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.SearchMySQLError,
code.MySQLExecError,
"SQL 语句不能为空!"),
)
return
@@ -106,7 +106,7 @@ func (h *handler) SearchMySQL() core.HandlerFunc {
if preFilterList[string([]byte(sql)[:6])] {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.SearchMySQLError,
code.MySQLExecError,
"SQL 语句不能以 "+string([]byte(sql)[:6])+" 开头!"),
)
return
@@ -126,7 +126,7 @@ func (h *handler) SearchMySQL() core.HandlerFunc {
if !isWhiteList {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.SearchMySQLError,
code.MySQLExecError,
"SQL 语句存在敏感词: "+f+""),
)
return
@@ -144,7 +144,7 @@ func (h *handler) SearchMySQL() core.HandlerFunc {
if err != nil {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.SearchMySQLError,
code.MySQLExecError,
"MySQL "+err.Error()).WithErr(err),
)
return
@@ -193,7 +193,7 @@ func (h *handler) SearchMySQL() core.HandlerFunc {
if err != nil {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.SearchMySQLError,
code.MySQLExecError,
"MySQL "+err.Error()).WithErr(err),
)
return
@@ -52,8 +52,8 @@ func (h *handler) Tables() core.HandlerFunc {
if err != nil {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.SearchMySQLError,
code.Text(code.SearchMySQLError)).WithErr(err),
code.MySQLExecError,
code.Text(code.MySQLExecError)).WithErr(err),
)
return
}
@@ -2,7 +2,7 @@ package admin_menu_repo
import "time"
// 管理员菜单栏表
// AdminMenu 管理员菜单栏表
//go:generate gormgen -structs AdminMenu -input .
type AdminMenu struct {
Id int32 // 主键
@@ -2,7 +2,7 @@ package admin_repo
import "time"
// 管理员表
// Admin 管理员表
//go:generate gormgen -structs Admin -input .
type Admin struct {
Id int32 // 主键
@@ -2,7 +2,7 @@ package authorized_api_repo
import "time"
// 已授权的调用方表
// AuthorizedApi 已授权的调用方表
//go:generate gormgen -structs AuthorizedApi -input .
type AuthorizedApi struct {
Id int32 // 主键
@@ -2,7 +2,7 @@ package authorized_repo
import "time"
// 已授权的调用方表
// Authorized 已授权的调用方表
//go:generate gormgen -structs Authorized -input .
type Authorized struct {
Id int32 // 主键
@@ -2,7 +2,7 @@ package menu_action_repo
import "time"
// 功能权限表
// MenuAction 功能权限表
//go:generate gormgen -structs MenuAction -input .
type MenuAction struct {
Id int32 // 主键
@@ -2,7 +2,7 @@ package menu_repo
import "time"
// 左侧菜单栏表
// Menu 左侧菜单栏表
//go:generate gormgen -structs Menu -input .
type Menu struct {
Id int32 // 主键
@@ -18,7 +18,7 @@ type CreateAuthorizedData struct {
func (s *service) Create(ctx core.Context, authorizedData *CreateAuthorizedData) (id int32, err error) {
buf := make([]byte, 10)
io.ReadFull(rand.Reader, buf)
secret := string(hex.EncodeToString(buf))
secret := hex.EncodeToString(buf)
model := authorized_repo.NewModel()
model.BusinessKey = authorizedData.BusinessKey
@@ -12,7 +12,7 @@ import (
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
)
// 定义缓存结构
// CacheAuthorizedData 缓存结构
type CacheAuthorizedData struct {
Key string `json:"key"` // 调用方 key
Secret string `json:"secret"` // 调用方 secret
+2 -3
View File
@@ -2,10 +2,9 @@ package third_party_request
import (
"github.com/xinliangnote/go-gin-api/configs"
"github.com/xinliangnote/go-gin-api/pkg/errors"
"github.com/xinliangnote/go-gin-api/pkg/httpclient"
"github.com/xinliangnote/go-gin-api/pkg/mail"
"github.com/pkg/errors"
)
// 实现 AlarmObject 告警
@@ -13,7 +12,7 @@ var _ httpclient.AlarmObject = (*AlarmEmail)(nil)
type AlarmEmail struct{}
// 邮件告警方式
// Send 邮件告警方式
func (a *AlarmEmail) Send(subject, body string) error {
cfg := configs.Get().Mail
if cfg.Host == "" || cfg.Port == 0 || cfg.User == "" || cfg.Pass == "" || cfg.To == "" {
@@ -17,7 +17,7 @@ type demoGetResponse struct {
Job string `json:"job"`
}
// 发起请求
// DemoGet 发起请求
func DemoGet(name string, opts ...httpclient.Option) (res *demoGetResponse, err error) {
api := demoGetApi + name
body, err := httpclient.Get(api, nil, opts...)
@@ -34,7 +34,7 @@ func DemoGet(name string, opts ...httpclient.Option) (res *demoGetResponse, err
return res, nil
}
// 设置重试规则
// DemoGetRetryVerify 设置重试规则
func DemoGetRetryVerify(body []byte) (shouldRetry bool) {
if len(body) == 0 {
return true
@@ -43,7 +43,7 @@ func DemoGetRetryVerify(body []byte) (shouldRetry bool) {
return false
}
// 设置告警规则
// DemoGetAlarmVerify 设置告警规则
func DemoGetAlarmVerify(body []byte) (shouldAlarm bool) {
if len(body) == 0 {
return true
@@ -52,7 +52,7 @@ func DemoGetAlarmVerify(body []byte) (shouldAlarm bool) {
return false
}
// 设置 Mock 数据
// DemoGetMock 设置 Mock 数据
func DemoGetMock() (body []byte) {
res := new(demoGetResponse)
res.Name = "AA"
@@ -18,7 +18,7 @@ type demoPostResponse struct {
Job string `json:"job"`
}
// 发起请求
// DemoPost 发起请求
func DemoPost(name string, opts ...httpclient.Option) (res *demoPostResponse, err error) {
api := demoPostApi
params := url.Values{}
@@ -37,7 +37,7 @@ func DemoPost(name string, opts ...httpclient.Option) (res *demoPostResponse, er
return res, nil
}
// 设置重试规则
// DemoPostRetryVerify 设置重试规则
func DemoPostRetryVerify(body []byte) (shouldRetry bool) {
if len(body) == 0 {
return true
@@ -46,7 +46,7 @@ func DemoPostRetryVerify(body []byte) (shouldRetry bool) {
return false
}
// 设置告警规则
// DemoPostAlarmVerify 设置告警规则
func DemoPostAlarmVerify(body []byte) (shouldAlarm bool) {
if len(body) == 0 {
return true
@@ -55,7 +55,7 @@ func DemoPostAlarmVerify(body []byte) (shouldAlarm bool) {
return false
}
// 设置 Mock 数据
// DemoPostMock 设置 Mock 数据
func DemoPostMock() (body []byte) {
res := new(demoPostResponse)
res.Name = "BB"
-1
View File
@@ -149,7 +149,6 @@ func (c *cacheRepo) ExpireAt(key string, ttl time.Time) bool {
return ok
}
//
func (c *cacheRepo) Exists(keys ...string) bool {
if len(keys) == 0 {
return true
+2 -2
View File
@@ -73,8 +73,8 @@ func WithDisableSwagger() Option {
}
}
// WithDisableproPrometheus 禁用prometheus
func WithDisableproPrometheus() Option {
// WithDisablePrometheus 禁用prometheus
func WithDisablePrometheus() Option {
return func(opt *option) {
opt.disablePrometheus = true
}
-1
View File
@@ -23,7 +23,6 @@ import (
)
const (
// Trace ID
TraceID = "trace-id"
)
+6 -6
View File
@@ -29,8 +29,8 @@ func (m *middleware) RBAC() core.HandlerFunc {
if !m.cache.Exists(configs.RedisKeyPrefixLoginUser + token) {
c.AbortWithError(errno.NewError(
http.StatusUnauthorized,
code.AuthorizationError,
code.Text(code.AuthorizationError)).WithErr(errors.New("请先登录 1")),
code.CacheGetError,
code.Text(code.CacheGetError)).WithErr(errors.New("请先登录 1")),
)
return
}
@@ -38,8 +38,8 @@ func (m *middleware) RBAC() core.HandlerFunc {
if !m.cache.Exists(configs.RedisKeyPrefixLoginUser + token + ":action") {
c.AbortWithError(errno.NewError(
http.StatusUnauthorized,
code.AuthorizationError,
code.Text(code.AuthorizationError)).WithErr(errors.New("请先登录 2")),
code.CacheGetError,
code.Text(code.CacheGetError)).WithErr(errors.New("请先登录 2")),
)
return
}
@@ -48,8 +48,8 @@ func (m *middleware) RBAC() core.HandlerFunc {
if err != nil {
c.AbortWithError(errno.NewError(
http.StatusUnauthorized,
code.AuthorizationError,
code.Text(code.AuthorizationError)).WithErr(err),
code.CacheGetError,
code.Text(code.CacheGetError)).WithErr(err),
)
return
}
@@ -23,8 +23,8 @@ func (m *middleware) Resubmit() core.HandlerFunc {
if err != nil {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.ResubmitError,
code.Text(code.ResubmitError)).WithErr(err),
code.UrlSignError,
code.Text(code.UrlSignError)).WithErr(err),
)
return
}
@@ -35,8 +35,8 @@ func (m *middleware) Resubmit() core.HandlerFunc {
if err != nil {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.ResubmitError,
code.Text(code.ResubmitError)).WithErr(err),
code.CacheSetError,
code.Text(code.CacheSetError)).WithErr(err),
)
return
}
@@ -48,8 +48,8 @@ func (m *middleware) Resubmit() core.HandlerFunc {
if err != nil {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.ResubmitError,
code.Text(code.ResubmitError)).WithErr(err),
code.CacheGetError,
code.Text(code.CacheGetError)).WithErr(err),
)
return
}
@@ -57,8 +57,8 @@ func (m *middleware) Resubmit() core.HandlerFunc {
if redisValue == reSubmitMark {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.ResubmitMsg,
code.Text(code.ResubmitMsg)).WithErr(errors.New("resubmit")),
code.ResubmitError,
code.Text(code.ResubmitError)).WithErr(errors.New("resubmit")),
)
return
}
+18 -18
View File
@@ -32,8 +32,8 @@ func (m *middleware) Signature() core.HandlerFunc {
if authorization == "" {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.SignatureError,
code.Text(code.SignatureError)).WithErr(errors.New("Header 中缺少 Authorization 参数")),
code.AuthorizationError,
code.Text(code.AuthorizationError)).WithErr(errors.New("Header 中缺少 Authorization 参数")),
)
return
}
@@ -43,8 +43,8 @@ func (m *middleware) Signature() core.HandlerFunc {
if date == "" {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.SignatureError,
code.Text(code.SignatureError)).WithErr(errors.New("Header 中缺少 Date 参数")),
code.AuthorizationError,
code.Text(code.AuthorizationError)).WithErr(errors.New("Header 中缺少 Date 参数")),
)
return
}
@@ -54,8 +54,8 @@ func (m *middleware) Signature() core.HandlerFunc {
if len(authorizationSplit) < minLength {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.SignatureError,
code.Text(code.SignatureError)).WithErr(errors.New("Header 中 Authorization 格式错误")),
code.AuthorizationError,
code.Text(code.AuthorizationError)).WithErr(errors.New("Header 中 Authorization 格式错误")),
)
return
}
@@ -66,8 +66,8 @@ func (m *middleware) Signature() core.HandlerFunc {
if err != nil {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.SignatureError,
code.Text(code.SignatureError)).WithErr(err),
code.AuthorizationError,
code.Text(code.AuthorizationError)).WithErr(err),
)
return
}
@@ -75,8 +75,8 @@ func (m *middleware) Signature() core.HandlerFunc {
if data.IsUsed == notUsed {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.SignatureError,
code.Text(code.SignatureError)).WithErr(errors.New(key + " 已被禁止调用")),
code.AuthorizationError,
code.Text(code.AuthorizationError)).WithErr(errors.New(key + " 已被禁止调用")),
)
return
}
@@ -84,8 +84,8 @@ func (m *middleware) Signature() core.HandlerFunc {
if len(data.Apis) < 1 {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.SignatureError,
code.Text(code.SignatureError)).WithErr(errors.New(key + " 未进行接口授权")),
code.AuthorizationError,
code.Text(code.AuthorizationError)).WithErr(errors.New(key + " 未进行接口授权")),
)
return
}
@@ -100,8 +100,8 @@ func (m *middleware) Signature() core.HandlerFunc {
if pattern, _ := table.Mapping(c.Method() + c.Path()); pattern == "" {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.SignatureError,
code.Text(code.SignatureError)).WithErr(errors.New(c.Method() + c.Path() + " 未进行接口授权")),
code.AuthorizationError,
code.Text(code.AuthorizationError)).WithErr(errors.New(c.Method() + c.Path() + " 未进行接口授权")),
)
return
}
@@ -111,8 +111,8 @@ func (m *middleware) Signature() core.HandlerFunc {
if err != nil {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.SignatureError,
code.Text(code.SignatureError)).WithErr(err),
code.AuthorizationError,
code.Text(code.AuthorizationError)).WithErr(err),
)
return
}
@@ -120,8 +120,8 @@ func (m *middleware) Signature() core.HandlerFunc {
if !ok {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.SignatureError,
code.Text(code.SignatureError)).WithErr(errors.New("Header 中 Authorization 信息错误")),
code.AuthorizationError,
code.Text(code.AuthorizationError)).WithErr(errors.New("Header 中 Authorization 信息错误")),
)
return
}
+1 -1
View File
@@ -17,7 +17,7 @@ type Middleware interface {
// i 为了避免被其他包实现
i()
// JWT 中间件
// Jwt 中间件
Jwt(ctx core.Context) (userId int64, userName string, err errno.Error)
// Resubmit 中间件
+2 -1
View File
@@ -39,12 +39,13 @@ func NewHTTPServer(logger *zap.Logger) (*Server, error) {
r := new(resource)
r.logger = logger
openBrowserUri := "http://127.0.0.1" + configs.ProjectPort
openBrowserUri := configs.ProjectDomain + configs.ProjectPort
_, ok := file.IsExists(configs.ProjectInstallMark)
if !ok { // 未安装
openBrowserUri += "/install"
} else { // 已安装
// 初始化 DB
dbRepo, err := db.New()
if err != nil {
-1
View File
@@ -36,7 +36,6 @@ func setWebRouter(r *resource) {
// 安装
notRBAC.GET("/install", installHandler.View())
notRBAC.POST("/install/execute", installHandler.Execute())
notRBAC.POST("/install/restart", installHandler.Restart())
// 管理员
notRBAC.GET("/login", adminHandler.LoginView())
@@ -19,7 +19,7 @@ func (h *handler) HandlerExecute() core.HandlerFunc {
dir, _ := os.Getwd()
projectPath := strings.Replace(dir, "\\", "/", -1)
handlergenSh := projectPath + "/scripts/handlergen.sh"
handlergenBat := projectPath + "./scripts/handlergen.bat"
handlergenBat := projectPath + "/scripts/handlergen.bat"
return func(c core.Context) {
req := new(handlerExecuteRequest)
@@ -22,6 +22,7 @@ import (
)
type initExecuteRequest struct {
Language string `form:"language" ` // 语言包
RedisAddr string `form:"redis_addr"` // 连接地址,例如:127.0.0.1:6379
RedisPass string `form:"redis_pass"` // 连接密码
RedisDb string `form:"redis_db"` // 连接 db
@@ -49,8 +50,8 @@ func (h *handler) Execute() core.HandlerFunc {
if version < 1.15 {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.ConfigGoVersionError,
code.Text(code.ConfigGoVersionError)),
code.GoVersionError,
code.Text(code.GoVersionError)),
)
return
}
@@ -70,8 +71,8 @@ func (h *handler) Execute() core.HandlerFunc {
if err := redisClient.Ping().Err(); err != nil {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.ConfigRedisConnectError,
code.Text(code.ConfigRedisConnectError)).WithErr(err),
code.RedisConnectError,
code.Text(code.RedisConnectError)).WithErr(err),
)
return
}
@@ -98,8 +99,8 @@ func (h *handler) Execute() core.HandlerFunc {
if err != nil {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.ConfigMySQLConnectError,
code.Text(code.ConfigMySQLConnectError)).WithErr(err),
code.MySQLConnectError,
code.Text(code.MySQLConnectError)).WithErr(err),
)
return
}
@@ -114,6 +115,9 @@ func (h *handler) Execute() core.HandlerFunc {
viper.SetConfigName(env.Active().Value() + "_configs")
viper.SetConfigType("toml")
viper.AddConfigPath("./configs")
viper.Set("language.local", req.Language)
viper.Set("redis.addr", req.RedisAddr)
viper.Set("redis.pass", req.RedisPass)
viper.Set("redis.db", req.RedisDb)
@@ -131,19 +135,20 @@ func (h *handler) Execute() core.HandlerFunc {
if viper.WriteConfig() != nil {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.ConfigSaveError,
code.Text(code.ConfigSaveError)).WithErr(err),
code.WriteConfigError,
code.Text(code.WriteConfigError)).WithErr(err),
)
return
}
outPutString += "语言包 " + req.Language + " 配置成功。\n"
outPutString += "配置项 Redis、MySQL 配置成功。\n"
if err = db.Exec(mysql_table.CreateAuthorizedTableSql()).Error; err != nil {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.ConfigMySQLInstallError,
"MySQL "+err.Error()).WithErr(err),
code.MySQLExecError,
code.Text(code.MySQLExecError)+" "+err.Error()).WithErr(err),
)
return
}
@@ -152,8 +157,8 @@ func (h *handler) Execute() core.HandlerFunc {
if err = db.Exec(mysql_table.CreateAuthorizedTableDataSql()).Error; err != nil {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.ConfigMySQLInstallError,
"MySQL "+err.Error()).WithErr(err),
code.MySQLExecError,
code.Text(code.MySQLExecError)+" "+err.Error()).WithErr(err),
)
return
}
@@ -162,8 +167,8 @@ func (h *handler) Execute() core.HandlerFunc {
if err = db.Exec(mysql_table.CreateAuthorizedAPITableSql()).Error; err != nil {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.ConfigMySQLInstallError,
"MySQL "+err.Error()).WithErr(err),
code.MySQLExecError,
code.Text(code.MySQLExecError)+" "+err.Error()).WithErr(err),
)
return
}
@@ -172,8 +177,8 @@ func (h *handler) Execute() core.HandlerFunc {
if err = db.Exec(mysql_table.CreateAuthorizedAPITableDataSql()).Error; err != nil {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.ConfigMySQLInstallError,
"MySQL "+err.Error()).WithErr(err),
code.MySQLExecError,
code.Text(code.MySQLExecError)+" "+err.Error()).WithErr(err),
)
return
}
@@ -182,8 +187,8 @@ func (h *handler) Execute() core.HandlerFunc {
if err = db.Exec(mysql_table.CreateAdminTableSql()).Error; err != nil {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.ConfigMySQLInstallError,
"MySQL "+err.Error()).WithErr(err),
code.MySQLExecError,
code.Text(code.MySQLExecError)+" "+err.Error()).WithErr(err),
)
return
}
@@ -192,8 +197,8 @@ func (h *handler) Execute() core.HandlerFunc {
if err = db.Exec(mysql_table.CreateAdminTableDataSql()).Error; err != nil {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.ConfigMySQLInstallError,
"MySQL "+err.Error()).WithErr(err),
code.MySQLExecError,
code.Text(code.MySQLExecError)+" "+err.Error()).WithErr(err),
)
return
}
@@ -202,8 +207,8 @@ func (h *handler) Execute() core.HandlerFunc {
if err = db.Exec(mysql_table.CreateMenuTableSql()).Error; err != nil {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.ConfigMySQLInstallError,
"MySQL "+err.Error()).WithErr(err),
code.MySQLExecError,
code.Text(code.MySQLExecError)+" "+err.Error()).WithErr(err),
)
return
}
@@ -212,8 +217,8 @@ func (h *handler) Execute() core.HandlerFunc {
if err = db.Exec(mysql_table.CreateMenuTableDataSql()).Error; err != nil {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.ConfigMySQLInstallError,
"MySQL "+err.Error()).WithErr(err),
code.MySQLExecError,
code.Text(code.MySQLExecError)+" "+err.Error()).WithErr(err),
)
return
}
@@ -222,8 +227,8 @@ func (h *handler) Execute() core.HandlerFunc {
if err = db.Exec(mysql_table.CreateMenuActionTableSql()).Error; err != nil {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.ConfigMySQLInstallError,
"MySQL "+err.Error()).WithErr(err),
code.MySQLExecError,
code.Text(code.MySQLExecError)+" "+err.Error()).WithErr(err),
)
return
}
@@ -232,8 +237,8 @@ func (h *handler) Execute() core.HandlerFunc {
if err = db.Exec(mysql_table.CreateMenuActionTableDataSql()).Error; err != nil {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.ConfigMySQLInstallError,
"MySQL "+err.Error()).WithErr(err),
code.MySQLExecError,
code.Text(code.MySQLExecError)+" "+err.Error()).WithErr(err),
)
return
}
@@ -242,8 +247,8 @@ func (h *handler) Execute() core.HandlerFunc {
if err = db.Exec(mysql_table.CreateAdminMenuTableSql()).Error; err != nil {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.ConfigMySQLInstallError,
"MySQL "+err.Error()).WithErr(err),
code.MySQLExecError,
code.Text(code.MySQLExecError)+" "+err.Error()).WithErr(err),
)
return
}
@@ -252,8 +257,8 @@ func (h *handler) Execute() core.HandlerFunc {
if err = db.Exec(mysql_table.CreateAdminMenuTableDataSql()).Error; err != nil {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.ConfigMySQLInstallError,
"MySQL "+err.Error()).WithErr(err),
code.MySQLExecError,
code.Text(code.MySQLExecError)+" "+err.Error()).WithErr(err),
)
return
}
@@ -264,8 +269,8 @@ func (h *handler) Execute() core.HandlerFunc {
if err != nil {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.ConfigMySQLInstallError,
"create lock file err: "+err.Error()).WithErr(err),
code.MySQLExecError,
code.Text(code.MySQLExecError)+" "+err.Error()).WithErr(err),
)
return
}
@@ -1,39 +0,0 @@
package install_handler
import (
"bytes"
"os/exec"
"runtime"
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
)
func (h *handler) Restart() core.HandlerFunc {
return func(c core.Context) {
shellPath := "./scripts/restart.sh"
command := new (exec.Cmd)
if runtime.GOOS == "windows" {
command = exec.Command("cmd", "/C", shellPath)
} else {
// runtime.GOOS = linux or darwin
command = exec.Command("/bin/bash", "-c", shellPath)
}
var stderr bytes.Buffer
command.Stderr = &stderr
outPutString := ""
output, err := command.Output()
if err != nil {
outPutString += stderr.String()
c.Payload(outPutString)
return
}
outPutString += string(output)
c.Payload(outPutString)
}
}
@@ -13,7 +13,6 @@ type Handler interface {
View() core.HandlerFunc
Execute() core.HandlerFunc
Restart() core.HandlerFunc
}
type handler struct {
@@ -2,7 +2,7 @@ package mysql_table
//CREATE TABLE `authorized_api` (
//`id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',
//`business_key` varchar(30) NOT NULL DEFAULT '' COMMENT '调用方key',
//`business_key` varchar(32) NOT NULL DEFAULT '' COMMENT '调用方key',
//`method` varchar(30) NOT NULL DEFAULT '' COMMENT '请求方式',
//`api` varchar(100) NOT NULL DEFAULT '' COMMENT '请求地址',
//`is_deleted` tinyint(1) NOT NULL DEFAULT '-1' COMMENT '是否删除 1:是 -1:否',
@@ -16,7 +16,7 @@ package mysql_table
func CreateAuthorizedAPITableSql() (sql string) {
sql = "CREATE TABLE `authorized_api` ("
sql += "`id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',"
sql += "`business_key` varchar(30) NOT NULL DEFAULT '' COMMENT '调用方key',"
sql += "`business_key` varchar(32) NOT NULL DEFAULT '' COMMENT '调用方key',"
sql += "`method` varchar(30) NOT NULL DEFAULT '' COMMENT '请求方式',"
sql += "`api` varchar(100) NOT NULL DEFAULT '' COMMENT '请求地址',"
sql += "`is_deleted` tinyint(1) NOT NULL DEFAULT '-1' COMMENT '是否删除 1:是 -1:否',"
@@ -33,8 +33,8 @@ func (h *handler) UpgradeExecute() core.HandlerFunc {
if err := db.Exec(mysql_table.CreateAuthorizedTableSql()).Error; err != nil {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.ConfigMySQLInstallError,
"MySQL "+err.Error()).WithErr(err),
code.MySQLExecError,
code.Text(code.MySQLExecError)+" "+err.Error()).WithErr(err),
)
return
}
@@ -45,8 +45,8 @@ func (h *handler) UpgradeExecute() core.HandlerFunc {
if err := db.Exec(mysql_table.CreateAuthorizedTableDataSql()).Error; err != nil {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.ConfigMySQLInstallError,
"MySQL "+err.Error()).WithErr(err),
code.MySQLExecError,
code.Text(code.MySQLExecError)+" "+err.Error()).WithErr(err),
)
return
}
@@ -57,8 +57,8 @@ func (h *handler) UpgradeExecute() core.HandlerFunc {
if err := db.Exec(mysql_table.CreateAuthorizedAPITableSql()).Error; err != nil {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.ConfigMySQLInstallError,
"MySQL "+err.Error()).WithErr(err),
code.MySQLExecError,
code.Text(code.MySQLExecError)+" "+err.Error()).WithErr(err),
)
return
}
@@ -69,8 +69,8 @@ func (h *handler) UpgradeExecute() core.HandlerFunc {
if err := db.Exec(mysql_table.CreateAuthorizedAPITableDataSql()).Error; err != nil {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.ConfigMySQLInstallError,
"MySQL "+err.Error()).WithErr(err),
code.MySQLExecError,
code.Text(code.MySQLExecError)+" "+err.Error()).WithErr(err),
)
return
}
@@ -81,8 +81,8 @@ func (h *handler) UpgradeExecute() core.HandlerFunc {
if err := db.Exec(mysql_table.CreateAdminTableSql()).Error; err != nil {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.ConfigMySQLInstallError,
"MySQL "+err.Error()).WithErr(err),
code.MySQLExecError,
code.Text(code.MySQLExecError)+" "+err.Error()).WithErr(err),
)
return
}
@@ -93,8 +93,8 @@ func (h *handler) UpgradeExecute() core.HandlerFunc {
if err := db.Exec(mysql_table.CreateAdminTableDataSql()).Error; err != nil {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.ConfigMySQLInstallError,
"MySQL "+err.Error()).WithErr(err),
code.MySQLExecError,
code.Text(code.MySQLExecError)+" "+err.Error()).WithErr(err),
)
return
}
@@ -105,8 +105,8 @@ func (h *handler) UpgradeExecute() core.HandlerFunc {
if err := db.Exec(mysql_table.CreateMenuTableSql()).Error; err != nil {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.ConfigMySQLInstallError,
"MySQL "+err.Error()).WithErr(err),
code.MySQLExecError,
code.Text(code.MySQLExecError)+" "+err.Error()).WithErr(err),
)
return
}
@@ -117,8 +117,8 @@ func (h *handler) UpgradeExecute() core.HandlerFunc {
if err := db.Exec(mysql_table.CreateMenuTableDataSql()).Error; err != nil {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.ConfigMySQLInstallError,
"MySQL "+err.Error()).WithErr(err),
code.MySQLExecError,
code.Text(code.MySQLExecError)+" "+err.Error()).WithErr(err),
)
return
}
@@ -129,8 +129,8 @@ func (h *handler) UpgradeExecute() core.HandlerFunc {
if err := db.Exec(mysql_table.CreateMenuActionTableSql()).Error; err != nil {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.ConfigMySQLInstallError,
"MySQL "+err.Error()).WithErr(err),
code.MySQLExecError,
code.Text(code.MySQLExecError)+" "+err.Error()).WithErr(err),
)
return
}
@@ -141,8 +141,8 @@ func (h *handler) UpgradeExecute() core.HandlerFunc {
if err := db.Exec(mysql_table.CreateMenuActionTableDataSql()).Error; err != nil {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.ConfigMySQLInstallError,
"MySQL "+err.Error()).WithErr(err),
code.MySQLExecError,
code.Text(code.MySQLExecError)+" "+err.Error()).WithErr(err),
)
return
}
@@ -153,8 +153,8 @@ func (h *handler) UpgradeExecute() core.HandlerFunc {
if err := db.Exec(mysql_table.CreateAdminMenuTableSql()).Error; err != nil {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.ConfigMySQLInstallError,
"MySQL "+err.Error()).WithErr(err),
code.MySQLExecError,
code.Text(code.MySQLExecError)+" "+err.Error()).WithErr(err),
)
return
}
@@ -165,8 +165,8 @@ func (h *handler) UpgradeExecute() core.HandlerFunc {
if err := db.Exec(mysql_table.CreateAdminMenuTableDataSql()).Error; err != nil {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.ConfigMySQLInstallError,
"MySQL "+err.Error()).WithErr(err),
code.MySQLExecError,
code.Text(code.MySQLExecError)+" "+err.Error()).WithErr(err),
)
return
}