代码规范过滤,移除冗余代码,替换掉不推荐的包

This commit is contained in:
孟帅
2023-05-30 12:09:40 +08:00
parent c8a808fcfd
commit b2ef3487d3
74 changed files with 564 additions and 741 deletions

View File

@@ -7,7 +7,6 @@ package admin
import (
"context"
"fmt"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"
@@ -241,7 +240,7 @@ func (s *sAdminCash) Apply(ctx context.Context, in adminin.CashApplyInp) (err er
CreditGroup: consts.CreditGroupApplyCash,
Num: -in.Money,
MapId: lastInsertId,
Remark: fmt.Sprintf("后台申请提现"),
Remark: "后台申请提现",
})
return

View File

@@ -298,6 +298,10 @@ func (s *sAdminOrder) List(ctx context.Context, in adminin.OrderListInp) (list [
{Dao: dao.PayLog, Alias: "payLog"},
})
if err != nil {
return
}
err = mod.Fields(fields).Page(in.Page, in.PerPage).OrderDesc(dao.AdminOrder.Columns().Id).Scan(&list)
return
}

View File

@@ -192,8 +192,7 @@ func (s *sCommonUpload) UploadUCloud(ctx context.Context, conf *model.UploadConf
}
nowDate := time.Now().Format("2006-01-02")
fileName := gfile.Basename(file.Filename)
fileName = strings.ToLower(strconv.FormatInt(gtime.TimestampNano(), 36) + grand.S(6))
fileName := strings.ToLower(strconv.FormatInt(gtime.TimestampNano(), 36) + grand.S(6))
fileName = fileName + gfile.Ext(file.Filename)
fullPath := conf.UCloudPath + nowDate + "/" + fileName
config := &ufile.Config{
@@ -213,7 +212,7 @@ func (s *sCommonUpload) UploadUCloud(ctx context.Context, conf *model.UploadConf
// 流式上传本地小文件
f2, err := file.Open()
defer f2.Close()
defer func() { _ = f2.Close() }()
if err != nil {
return
}
@@ -243,14 +242,13 @@ func (s *sCommonUpload) UploadCOS(ctx context.Context, conf *model.UploadConfig,
}
nowDate := time.Now().Format("2006-01-02")
fileName := gfile.Basename(file.Filename)
fileName = strings.ToLower(strconv.FormatInt(gtime.TimestampNano(), 36) + grand.S(6))
fileName := strings.ToLower(strconv.FormatInt(gtime.TimestampNano(), 36) + grand.S(6))
fileName = fileName + gfile.Ext(file.Filename)
fullPath := conf.CosPath + nowDate + "/" + fileName
// 流式上传本地小文件
f2, err := file.Open()
defer f2.Close()
defer func() { _ = f2.Close() }()
if err != nil {
return
}
@@ -289,14 +287,13 @@ func (s *sCommonUpload) UploadOSS(ctx context.Context, conf *model.UploadConfig,
}
nowDate := time.Now().Format("2006-01-02")
fileName := gfile.Basename(file.Filename)
fileName = strings.ToLower(strconv.FormatInt(gtime.TimestampNano(), 36) + grand.S(6))
fileName := strings.ToLower(strconv.FormatInt(gtime.TimestampNano(), 36) + grand.S(6))
fileName = fileName + gfile.Ext(file.Filename)
fullPath := conf.OssPath + nowDate + "/" + fileName
// 流式上传本地小文件
f2, err := file.Open()
defer f2.Close()
defer func() { _ = f2.Close() }()
if err != nil {
return
}
@@ -336,14 +333,13 @@ func (s *sCommonUpload) UploadQiNiu(ctx context.Context, conf *model.UploadConfi
}
nowDate := time.Now().Format("2006-01-02")
fileName := gfile.Basename(file.Filename)
fileName = strings.ToLower(strconv.FormatInt(gtime.TimestampNano(), 36) + grand.S(6))
fileName := strings.ToLower(strconv.FormatInt(gtime.TimestampNano(), 36) + grand.S(6))
fileName = fileName + gfile.Ext(file.Filename)
fullPath := conf.QiNiuPath + nowDate + "/" + fileName
// 流式上传本地小文件
f2, err := file.Open()
defer f2.Close()
defer func() { _ = f2.Close() }()
if err != nil {
return
}

View File

@@ -49,7 +49,7 @@ func NewCommonWechat() *sCommonWechat {
func init() {
serv := NewCommonWechat()
service.RegisterCommonWechat(serv)
gcron.Add(gctx.New(), "@every 300s", serv.CleanTempMap, "WechatCleanTempMap")
_, _ = gcron.Add(gctx.New(), "@every 300s", serv.CleanTempMap, "WechatCleanTempMap")
}
// Authorize 微信用户授权
@@ -116,7 +116,7 @@ func (s *sCommonWechat) AuthorizeCall(ctx context.Context, in commonin.WechatAut
switch data.Type {
case consts.WechatAuthorizeOpenId: // 设置openid
cache.Instance().Set(ctx, data.State, tk.OpenID, time.Hour*24*7)
_ = cache.Instance().Set(ctx, data.State, tk.OpenID, time.Hour*24*7)
case consts.WechatAuthorizeBindLogin: // 绑定微信登录
// ...
default:

View File

@@ -80,10 +80,10 @@ func (s *sSysAddons) List(ctx context.Context, in sysin.AddonsListInp) (list []*
}
if row.Skeleton.Logo == "" {
row.Skeleton.Logo, _ = consts.AddonsGroupIconMap[row.Skeleton.Group]
row.Skeleton.Logo = consts.AddonsGroupIconMap[row.Skeleton.Group]
}
row.GroupName, _ = consts.AddonsGroupNameMap[row.Skeleton.Group]
row.GroupName = consts.AddonsGroupNameMap[row.Skeleton.Group]
list = append(list, row)
i++

View File

@@ -158,7 +158,7 @@ func (s *sSysBlacklist) Load(ctx context.Context) {
for _, v := range array {
list := convert.IpFilterStrategy(v.String())
if len(list) > 0 {
for k, _ := range list {
for k := range list {
global.Blacklists[k] = struct{}{}
}
}

View File

@@ -84,7 +84,7 @@ func (s *sSysCron) Edit(ctx context.Context, in sysin.CronEditInp) (err error) {
return
}
simple.SafeGo(ctx, func(ctx context.Context) {
crons.RefreshStatus(&in.SysCron)
_ = crons.RefreshStatus(&in.SysCron)
})
return
}
@@ -123,11 +123,12 @@ func (s *sSysCron) Status(ctx context.Context, in sysin.CronStatusInp) (err erro
_, err = dao.SysCron.Ctx(ctx).Where("id", in.Id).Data("status", in.Status).Update()
if err != nil {
return
}
models.Status = in.Status
simple.SafeGo(ctx, func(ctx context.Context) {
crons.RefreshStatus(models)
_ = crons.RefreshStatus(models)
})
return
}
@@ -151,7 +152,6 @@ func (s *sSysCron) View(ctx context.Context, in sysin.CronViewInp) (res *sysin.C
if err = dao.SysCron.Ctx(ctx).Where("id", in.Id).Scan(&res); err != nil {
return
}
return
}

View File

@@ -87,6 +87,10 @@ func (s *sSysCurdDemo) List(ctx context.Context, in sysin.CurdDemoListInp) (list
{Dao: dao.TestCategory, Alias: "testCategory"},
})
if err != nil {
return
}
if err = mod.Fields(fields).Page(in.Page, in.PerPage).OrderAsc(dao.SysGenCurdDemo.Columns().Sort).OrderDesc(dao.SysGenCurdDemo.Columns().Id).Scan(&list); err != nil {
err = gerror.Wrap(err, "获取生成演示列表失败,请稍后重试!")
return

View File

@@ -281,7 +281,6 @@ func (s *sSysEmsLog) newView(ctx context.Context, in sysin.SendEmsInp, config *m
}
view.Assign("passwordResetLink", passwordResetLink)
}
return
}
@@ -308,7 +307,6 @@ func (s *sSysEmsLog) GetTemplate(ctx context.Context, template string, config *m
return v.Value, nil
}
}
return
}
@@ -346,7 +344,6 @@ func (s *sSysEmsLog) AllowSend(ctx context.Context, models *entity.SysEmsLog, co
return err
}
}
return
}
@@ -400,7 +397,7 @@ func (s *sSysEmsLog) VerifyCode(ctx context.Context, in sysin.VerifyEmsCodeInp)
}
if models.Code != in.Code {
dao.SysEmsLog.Ctx(ctx).Where("id", models.Id).Increment("times", 1)
_, _ = dao.SysEmsLog.Ctx(ctx).Where("id", models.Id).Increment("times", 1)
err = gerror.New("验证码错误!")
return
}

View File

@@ -238,11 +238,10 @@ func (s *sSysGenCodes) TableSelect(ctx context.Context, in sysin.GenCodesTableSe
bt, err := gregex.Replace(patternStr, []byte(repStr), []byte(newValue))
if err != nil {
err = gerror.Newf("表名[%v] gregex.Replace err:%v", v.Value, err.Error())
break
return nil, err
}
row := new(sysin.GenCodesTableSelectModel)
row = v
row := v
row.DefTableComment = v.Label
row.DaoName = gstr.CaseCamel(newValue)
row.DefVarName = gstr.CaseCamel(string(bt))
@@ -252,7 +251,6 @@ func (s *sSysGenCodes) TableSelect(ctx context.Context, in sysin.GenCodesTableSe
res = append(res, row)
}
return
}

View File

@@ -129,7 +129,6 @@ func (s *sSysLog) AutoLog(ctx context.Context) error {
}
err = s.RealWrite(ctx, data)
return
})
}
@@ -331,14 +330,14 @@ func (s *sSysLog) List(ctx context.Context, in sysin.LogListInp) (list []*sysin.
list[i].MemberName = memberName.String()
}
// 接口
if list[i].AppId == consts.AppApi {
//memberName, err = dao.Member.Ctx(ctx).Fields("realname").Where("id", res.List[i].MemberId).Value()
//if err != nil {
// err = gerror.Wrap(err, consts.ErrorORM)
// return nil, err
//}
}
//// 接口
//if list[i].AppId == consts.AppApi {
// //memberName, err = dao.Member.Ctx(ctx).Fields("realname").Where("id", res.List[i].MemberId).Value()
// //if err != nil {
// // err = gerror.Wrap(err, consts.ErrorORM)
// // return nil, err
// //}
//}
if list[i].MemberName == "" {
list[i].MemberName = "游客"

View File

@@ -88,6 +88,10 @@ func (s *sSysLoginLog) List(ctx context.Context, in sysin.LoginLogListInp) (list
{Dao: dao.SysLog, Alias: "sysLog"},
})
if err != nil {
return
}
if err = mod.Fields(fields).Hook(hook.CityLabel).Handler(handler.FilterAuth).Page(in.Page, in.PerPage).OrderDesc(dao.SysLoginLog.Columns().Id).Scan(&list); err != nil {
err = gerror.Wrap(err, consts.ErrorORM)
return list, totalCount, err
@@ -172,7 +176,6 @@ func (s *sSysLoginLog) Push(ctx context.Context, in sysin.LoginLogPushInp) {
if err := queue.Push(consts.QueueLoginLogTopic, models); err != nil {
g.Log().Warningf(ctx, "push err:%+v, models:%+v", err, models)
}
return
}
// RealWrite 真实写入

View File

@@ -77,6 +77,10 @@ func (s *sSysServeLog) List(ctx context.Context, in sysin.ServeLogListInp) (list
{Dao: dao.SysLog, Alias: "sysLog"},
})
if err != nil {
return
}
err = mod.Fields(fields).Handler(handler.FilterAuth).Page(in.Page, in.PerPage).OrderDesc(dao.SysServeLog.Columns().Id).Scan(&list)
return
}

View File

@@ -15,6 +15,7 @@ import (
"hotgo/internal/consts"
"hotgo/internal/dao"
"hotgo/internal/library/location"
"hotgo/internal/library/sms"
"hotgo/internal/model"
"hotgo/internal/model/entity"
"hotgo/internal/model/input/form"
@@ -140,7 +141,6 @@ func (s *sSysSmsLog) List(ctx context.Context, in sysin.SmsLogListInp) (list []*
err = gerror.Wrap(err, consts.ErrorORM)
return list, totalCount, err
}
return list, totalCount, err
}
@@ -179,9 +179,9 @@ func (s *sSysSmsLog) SendCode(ctx context.Context, in sysin.SendCodeInp) (err er
in.Code = grand.Digits(4)
}
//if err = sms.New(config.SmsDrive).SendCode(ctx, in, config); err != nil {
// return
//}
if err = sms.New(config.SmsDrive).SendCode(ctx, in, config); err != nil {
return
}
var data = new(entity.SysSmsLog)
data.Event = in.Event
@@ -237,7 +237,6 @@ func (s *sSysSmsLog) GetTemplate(ctx context.Context, template string, config *m
err = gerror.Newf("暂不支持短信驱动:%v", config.SmsDrive)
return
}
return
}
@@ -269,7 +268,6 @@ func (s *sSysSmsLog) AllowSend(ctx context.Context, models *entity.SysSmsLog, co
return err
}
}
return
}
@@ -319,7 +317,7 @@ func (s *sSysSmsLog) VerifyCode(ctx context.Context, in sysin.VerifyCodeInp) (er
}
if models.Code != in.Code {
dao.SysSmsLog.Ctx(ctx).Where("id", models.Id).Increment("times", 1)
_, _ = dao.SysSmsLog.Ctx(ctx).Where("id", models.Id).Increment("times", 1)
err = gerror.New("验证码错误!")
return
}
@@ -329,6 +327,5 @@ func (s *sSysSmsLog) VerifyCode(ctx context.Context, in sysin.VerifyCodeInp) (er
"status": consts.SmsStatusUsed,
"updated_at": gtime.Now(),
}).Update()
return
}

View File

@@ -93,7 +93,7 @@ func (s *sAuthClient) IsLogin() bool {
func (s *sAuthClient) onLoginEvent() {
// 获取授权数据
s.client.Send(s.client.Ctx, &msgin.AuthSummary{})
_ = s.client.Send(s.client.Ctx, &msgin.AuthSummary{})
}
// onCloseEvent 连接关闭回调事件

View File

@@ -10,12 +10,12 @@ import (
func (s *sAuthClient) OnResponseAuthSummary(ctx context.Context, args ...interface{}) {
var in *msgin.ResponseAuthSummary
if err := gconv.Scan(args[0], &in); err != nil {
s.client.Logger.Warningf(ctx, "OnResponseAuthSummary Scan err:+v", err)
s.client.Logger.Warningf(ctx, "OnResponseAuthSummary Scan err:%+v", err)
return
}
if err := in.GetError(); err != nil {
s.client.Logger.Warningf(ctx, "OnResponseAuthSummary GetError :+v", err)
s.client.Logger.Warningf(ctx, "OnResponseAuthSummary GetError:%+v", err)
return
}

View File

@@ -17,7 +17,7 @@ func (s *sCronClient) OnCronDelete(ctx context.Context, args ...interface{}) {
if err := gconv.Scan(args[0], &in); err != nil {
res.Code = 1
res.Message = err.Error()
s.client.Reply(ctx, res)
_ = s.client.Reply(ctx, res)
return
}
@@ -26,7 +26,7 @@ func (s *sCronClient) OnCronDelete(ctx context.Context, args ...interface{}) {
res.Message = err.Error()
}
s.client.Reply(ctx, res)
_ = s.client.Reply(ctx, res)
}
// OnCronEdit 编辑任务
@@ -39,7 +39,7 @@ func (s *sCronClient) OnCronEdit(ctx context.Context, args ...interface{}) {
if err := gconv.Scan(args[0], &in); err != nil {
res.Code = 1
res.Message = err.Error()
s.client.Reply(ctx, res)
_ = s.client.Reply(ctx, res)
return
}
@@ -48,7 +48,7 @@ func (s *sCronClient) OnCronEdit(ctx context.Context, args ...interface{}) {
res.Message = err.Error()
}
s.client.Reply(ctx, res)
_ = s.client.Reply(ctx, res)
}
// OnCronStatus 修改任务状态
@@ -61,7 +61,7 @@ func (s *sCronClient) OnCronStatus(ctx context.Context, args ...interface{}) {
if err := gconv.Scan(args[0], &in); err != nil {
res.Code = 1
res.Message = err.Error()
s.client.Reply(ctx, res)
_ = s.client.Reply(ctx, res)
return
}
@@ -70,7 +70,7 @@ func (s *sCronClient) OnCronStatus(ctx context.Context, args ...interface{}) {
res.Message = err.Error()
}
s.client.Reply(ctx, res)
_ = s.client.Reply(ctx, res)
}
// OnCronOnlineExec 执行一次任务
@@ -83,7 +83,7 @@ func (s *sCronClient) OnCronOnlineExec(ctx context.Context, args ...interface{})
if err := gconv.Scan(args[0], &in); err != nil {
res.Code = 1
res.Message = err.Error()
s.client.Reply(ctx, res)
_ = s.client.Reply(ctx, res)
return
}
@@ -92,5 +92,5 @@ func (s *sCronClient) OnCronOnlineExec(ctx context.Context, args ...interface{})
res.Message = err.Error()
}
s.client.Reply(ctx, res)
_ = s.client.Reply(ctx, res)
}

View File

@@ -23,54 +23,54 @@ func (s *sTCPServer) OnAuthSummary(ctx context.Context, args ...interface{}) {
if err := gconv.Scan(args, &in); err != nil {
res.Code = 1
res.Message = err.Error()
s.serv.Reply(ctx, res)
_ = s.serv.Reply(ctx, res)
return
}
if user.Auth == nil {
res.Code = 2
res.Message = "登录信息获取失败,请重新登录"
s.serv.Reply(ctx, res)
_ = s.serv.Reply(ctx, res)
return
}
if err := dao.SysServeLicense.Ctx(ctx).Where("appid = ?", user.Auth.AppId).Scan(&models); err != nil {
res.Code = 3
res.Message = err.Error()
s.serv.Reply(ctx, res)
_ = s.serv.Reply(ctx, res)
return
}
if models == nil {
res.Code = 4
res.Message = "授权信息不存在"
s.serv.Reply(ctx, res)
_ = s.serv.Reply(ctx, res)
return
}
if models.Status != consts.StatusEnabled {
res.Code = 5
res.Message = "授权已禁用,请联系管理员"
s.serv.Reply(ctx, res)
_ = s.serv.Reply(ctx, res)
return
}
if models.Group != user.Auth.Group {
res.Code = 6
res.Message = "你登录的授权分组未得到授权,请联系管理员"
s.serv.Reply(ctx, res)
_ = s.serv.Reply(ctx, res)
return
}
if models.EndAt.Before(gtime.Now()) {
res.Code = 7
res.Message = "授权已过期,请联系管理员"
s.serv.Reply(ctx, res)
_ = s.serv.Reply(ctx, res)
return
}
res.Data = new(msgin.AuthSummaryData)
res.Data.EndAt = models.EndAt
res.Data.Online = models.Online
s.serv.Reply(ctx, res)
_ = s.serv.Reply(ctx, res)
}

View File

@@ -3,14 +3,11 @@
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
//
package view
import (
"context"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gfile"
"github.com/gogf/gf/v2/text/gstr"
"github.com/gogf/gf/v2/util/gconv"
"hotgo/internal/model"
"hotgo/internal/service"
@@ -42,9 +39,8 @@ func (s *sView) GetTitle(ctx context.Context, in *model.ViewGetTitleInput) strin
// RenderTpl 渲染指定模板页面
func (s *sView) RenderTpl(ctx context.Context, tpl string, data ...model.View) {
var (
viewObj = model.View{}
viewData = make(g.Map)
request = g.RequestFromCtx(ctx)
viewObj = model.View{}
request = g.RequestFromCtx(ctx)
)
if len(data) > 0 {
viewObj = data[0]
@@ -69,7 +65,7 @@ func (s *sView) RenderTpl(ctx context.Context, tpl string, data ...model.View) {
}
// 去掉空数据
viewData = gconv.Map(viewObj)
viewData := gconv.Map(viewObj)
for k, v := range viewData {
if g.IsEmpty(v) {
delete(viewData, k)
@@ -96,8 +92,6 @@ func (s *sView) Render302(ctx context.Context, data ...model.View) {
if view.Title == "" {
view.Title = "页面跳转中"
}
//view.MainTpl = s.getViewFolderName(ctx) + "/pages/302.html"
//s.Render(ctx, view)
s.RenderTpl(ctx, "default/pages/302.html", view)
}
@@ -156,37 +150,3 @@ func (s *sView) Error(ctx context.Context, err error) {
}
s.RenderTpl(ctx, "default/pages/500.html", view)
}
// 获取视图存储目录
func (s *sView) getViewFolderName(ctx context.Context) string {
return gstr.Split(g.Cfg().MustGet(ctx, "viewer.indexLayout").String(), "/")[0]
}
// 获取自动设置的MainTpl
func (s *sView) getDefaultMainTpl(ctx context.Context) string {
var (
viewFolderPrefix = s.getViewFolderName(ctx)
urlPathArray = gstr.SplitAndTrim(g.RequestFromCtx(ctx).URL.Path, "/")
mainTpl string
)
if len(urlPathArray) > 0 && urlPathArray[0] == viewFolderPrefix {
urlPathArray = urlPathArray[1:]
}
switch {
case len(urlPathArray) == 2:
// 如果2级路由为数字那么为模块的详情页面那么路由固定为/xxx/detail。
// 如果需要定制化内容模板请在具体路由方法中设置MainTpl。
if gstr.IsNumeric(urlPathArray[1]) {
urlPathArray[1] = "detail"
}
mainTpl = viewFolderPrefix + "/" + gfile.Join(urlPathArray[0], urlPathArray[1]) + ".html"
case len(urlPathArray) == 1:
mainTpl = viewFolderPrefix + "/" + urlPathArray[0] + "/index.html"
default:
// 默认首页内容
mainTpl = viewFolderPrefix + "/index/index.html"
}
return gstr.TrimLeft(mainTpl, "/")
}