From 2d0d7e5604edb979eb0054a6b14a4a00a627cf92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=9F=E5=B8=85?= <133814250@qq.com> Date: Thu, 15 Jun 2023 20:40:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96home=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E9=94=99=E8=AF=AF=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/api/home/base/site.go | 2 +- server/internal/controller/home/base/site.go | 10 +- server/internal/logic/middleware/home_auth.go | 15 + server/internal/logic/middleware/response.go | 115 ++++--- server/internal/logic/view/view.go | 84 ++---- server/internal/router/home.go | 14 +- server/internal/service/admin.go | 254 ++++++++-------- server/internal/service/middleware.go | 1 + server/internal/service/sys.go | 282 +++++++++--------- server/internal/service/tcpclient.go | 12 +- server/internal/service/view.go | 5 - server/resource/template/error/default.html | 94 ++++++ server/utility/charset/charset.go | 12 + server/utility/simple/simple.go | 6 + 14 files changed, 509 insertions(+), 397 deletions(-) create mode 100644 server/internal/logic/middleware/home_auth.go create mode 100644 server/resource/template/error/default.html diff --git a/server/api/home/base/site.go b/server/api/home/base/site.go index 4920b4f..d70f5ba 100644 --- a/server/api/home/base/site.go +++ b/server/api/home/base/site.go @@ -8,7 +8,7 @@ package base import "github.com/gogf/gf/v2/frame/g" type SiteIndexReq struct { - g.Meta `path:"/index" method:"get" summary:"首页" tags:"首页"` + g.Meta `path:"/" method:"get" summary:"首页" tags:"首页"` } type SiteIndexRes struct { diff --git a/server/internal/controller/home/base/site.go b/server/internal/controller/home/base/site.go index 63e6ff4..ebb7b11 100644 --- a/server/internal/controller/home/base/site.go +++ b/server/internal/controller/home/base/site.go @@ -24,7 +24,15 @@ func (a *cSite) Index(ctx context.Context, _ *base.SiteIndexReq) (res *base.Site service.View().Render(ctx, model.View{Data: g.Map{ "name": simple.AppName(ctx), "version": consts.VersionApp, - "debug": g.Cfg().MustGet(ctx, "hotgo.debug", true), }}) + + //err = gerror.New("这是一个测试错误") + //return + + //err = gerror.NewCode(gcode.New(10000, "这是一个测试自定义错误码错误", nil)) + //return + + //service.View().Error(ctx, gerror.New("这是一个允许被自定义格式的错误,默认和通用错误格式一致,你可以修改它")) + //return return } diff --git a/server/internal/logic/middleware/home_auth.go b/server/internal/logic/middleware/home_auth.go new file mode 100644 index 0000000..27e5dd4 --- /dev/null +++ b/server/internal/logic/middleware/home_auth.go @@ -0,0 +1,15 @@ +package middleware + +import ( + "github.com/gogf/gf/v2/net/ghttp" +) + +// HomeAuth 前台页面鉴权中间件 +func (s *sMiddleware) HomeAuth(r *ghttp.Request) { + r.Response.Header().Set("Content-Type", "text/html") + + // 鉴权 + // ... + + r.Middleware.Next() +} diff --git a/server/internal/logic/middleware/response.go b/server/internal/logic/middleware/response.go index c02fb09..298ecfa 100644 --- a/server/internal/logic/middleware/response.go +++ b/server/internal/logic/middleware/response.go @@ -17,15 +17,22 @@ import ( "hotgo/internal/library/response" "hotgo/internal/model/input/payin" "hotgo/utility/charset" + "hotgo/utility/simple" + "net/http" ) // ResponseHandler HTTP响应预处理 func (s *sMiddleware) ResponseHandler(r *ghttp.Request) { r.Middleware.Next() - // 模板页面响应 - if "text/html" == r.Response.Header().Get("Content-Type") { - r.Middleware.Next() + // 已存在响应 + if r.Response.BufferLength() > 0 && contexts.Get(r.Context()).Response != nil { + return + } + + // html模板响应 + if r.Response.Header().Get("Content-Type") == "text/html" { + s.responseHtml(r) return } @@ -35,10 +42,27 @@ func (s *sMiddleware) ResponseHandler(r *ghttp.Request) { return } + // 默认json响应 responseJson(r) } -// rTemplate 支付通知响应 +// responseHtml html模板响应 +func (s *sMiddleware) responseHtml(r *ghttp.Request) { + code, message, resp := parseResponse(r) + if code == gcode.CodeOK.Code() { + return + } + + r.Response.ClearBuffer() + _ = r.Response.WriteTplContent(simple.DefaultErrorTplContent(r.Context()), g.Map{ + "code": code, + "message": message, + "stack": resp, + }) + return +} + +// responsePayNotify 支付通知响应 func (s *sMiddleware) responsePayNotify(r *ghttp.Request) { var ( ctx = r.Context() @@ -46,18 +70,16 @@ func (s *sMiddleware) responsePayNotify(r *ghttp.Request) { data *payin.PayNotifyModel ) - // 异常 - if err = r.GetError(); err != nil { - g.Log("exception").Error(ctx, err) - r.Response.ClearBuffer() - r.Response.WriteStatus(500, err.Error()) + code, message, resp := parseResponse(r) + if code != gcode.CodeOK.Code() { + response.RJson(r, code, message, data) return } - if err = gconv.Scan(r.GetHandlerResponse(), &data); err != nil || data == nil { + if err = gconv.Scan(resp, &data); err != nil || data == nil { g.Log("exception").Errorf(ctx, "middleware.responsePayNotify Scan err:%+v, data:%+v", err, data) r.Response.ClearBuffer() - r.Response.WriteStatus(500, err.Error()) + r.Response.WriteStatus(http.StatusInternalServerError, err.Error()) return } @@ -80,46 +102,43 @@ func (s *sMiddleware) responsePayNotify(r *ghttp.Request) { err = gerror.Newf("无效的支付方式,这可能是没有配置通知回调响应方式导致的:%+v", data) g.Log("exception").Error(ctx, err) r.Response.ClearBuffer() - r.Response.WriteStatus(500, err.Error()) + r.Response.WriteStatus(http.StatusInternalServerError, err.Error()) } } +// responseJson json响应 func responseJson(r *ghttp.Request) { - var ( - ctx = r.Context() - comResponse = contexts.Get(ctx).Response - code = gcode.CodeOK.Code() - message = "操作成功" - data interface{} - err error - ) - - // 已存在响应内容,且是comResponse返回的时,中断运行 - if r.Response.BufferLength() > 0 && comResponse != nil { - return - } - - if err = r.GetError(); err != nil { - // 记录到自定义错误日志文件 - code = gerror.Code(err).Code() - - if code == gcode.CodeNil.Code() { - g.Log().Stdout(false).Printf(ctx, "exception:%v", err) - } else { - g.Log().Errorf(ctx, "exception:%v", err) - } - - // 是否输出错误到页面 - if g.Cfg().MustGet(ctx, "hotgo.debug", true).Bool() { - message = gerror.Current(err).Error() - data = charset.ParseErrStack(err) - } else { - message = consts.ErrorMessage(gerror.Current(err)) - } - } else { - data = r.GetHandlerResponse() - } - - // 返回固定的友好信息 + code, message, data := parseResponse(r) response.RJson(r, code, message, data) } + +// parseResponse 解析响应数据 +func parseResponse(r *ghttp.Request) (code int, message string, resp interface{}) { + var ( + ctx = r.Context() + err = r.GetError() + ) + + if err == nil { + return gcode.CodeOK.Code(), "操作成功", r.GetHandlerResponse() + } + + // 是否输出错误堆栈到页面 + if g.Cfg().MustGet(ctx, "hotgo.debug", true).Bool() { + message = gerror.Current(err).Error() + resp = charset.ParseErrStack(err) + } else { + message = consts.ErrorMessage(gerror.Current(err)) + } + + // 解析错误状态码 + code = gerror.Code(err).Code() + + // 记录异常日志 + if code == gcode.CodeNil.Code() { + g.Log().Stdout(false).Printf(ctx, "exception:%v", err) + } else { + g.Log().Errorf(ctx, "exception:%v", err) + } + return +} diff --git a/server/internal/logic/view/view.go b/server/internal/logic/view/view.go index 4c2c774..dd86ad0 100644 --- a/server/internal/logic/view/view.go +++ b/server/internal/logic/view/view.go @@ -7,10 +7,13 @@ package view import ( "context" + "github.com/gogf/gf/v2/errors/gerror" "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/util/gconv" "hotgo/internal/model" "hotgo/internal/service" + "hotgo/utility/charset" + "hotgo/utility/simple" ) type sView struct{} @@ -83,70 +86,23 @@ func (s *sView) Render(ctx context.Context, data ...model.View) { s.RenderTpl(ctx, g.Cfg().MustGet(ctx, "viewer.homeLayout").String(), data...) } -// Render302 跳转中间页面 -func (s *sView) Render302(ctx context.Context, data ...model.View) { - view := model.View{} - if len(data) > 0 { - view = data[0] - } - if view.Title == "" { - view.Title = "页面跳转中" - } - s.RenderTpl(ctx, "default/pages/302.html", view) -} - -// Render401 401页面 -func (s *sView) Render401(ctx context.Context, data ...model.View) { - view := model.View{} - if len(data) > 0 { - view = data[0] - } - if view.Title == "" { - view.Title = "无访问权限" - } - s.RenderTpl(ctx, "default/pages/401.html", view) -} - -// Render403 403页面 -func (s *sView) Render403(ctx context.Context, data ...model.View) { - view := model.View{} - if len(data) > 0 { - view = data[0] - } - if view.Title == "" { - view.Title = "无访问权限" - } - s.RenderTpl(ctx, "default/pages/403.html", view) -} - -// Render404 404页面 -func (s *sView) Render404(ctx context.Context, data ...model.View) { - view := model.View{} - if len(data) > 0 { - view = data[0] - } - if view.Title == "" { - view.Title = "资源不存在" - } - s.RenderTpl(ctx, "default/pages/404.html", view) -} - -// Render500 500页面 -func (s *sView) Render500(ctx context.Context, data ...model.View) { - view := model.View{} - if len(data) > 0 { - view = data[0] - } - if view.Title == "" { - view.Title = "请求执行错误" - } - s.RenderTpl(ctx, "default/pages/500.html", view) -} - +// Error 自定义错误页面 func (s *sView) Error(ctx context.Context, err error) { - view := model.View{ - Title: "错误提示", - Error: err.Error(), + var ( + request = g.RequestFromCtx(ctx) + code = gerror.Code(err) + stack string + ) + + // 是否输出错误堆栈到页面 + if g.Cfg().MustGet(ctx, "hotgo.debug", true).Bool() { + stack = charset.SerializeStack(err) } - s.RenderTpl(ctx, "default/pages/500.html", view) + + request.Response.ClearBuffer() + _ = request.Response.WriteTplContent(simple.DefaultErrorTplContent(ctx), g.Map{ + "code": code.Code(), + "message": code.Message(), + "stack": stack, + }) } diff --git a/server/internal/router/home.go b/server/internal/router/home.go index 9ddb930..02c9798 100644 --- a/server/internal/router/home.go +++ b/server/internal/router/home.go @@ -8,19 +8,25 @@ package router import ( "context" "github.com/gogf/gf/v2/net/ghttp" - api "hotgo/api/home/base" "hotgo/internal/consts" "hotgo/internal/controller/home/base" + "hotgo/internal/service" "hotgo/utility/simple" ) // Home 前台页面路由 func Home(ctx context.Context, group *ghttp.RouterGroup) { - // 注册首页路由 - group.ALL("/", func(r *ghttp.Request) { - _, _ = base.Site.Index(r.Context(), &api.SiteIndexReq{}) + group.Middleware(service.Middleware().HomeAuth) + + // 允许通过根地址访问的路由可以同时加到这里 + // 访问地址:http://127.0.0.1:8000 + group.Group("/", func(group *ghttp.RouterGroup) { + group.Bind( + base.Site, // 基础 + ) }) + // 默认访问地址:http://127.0.0.1:8000/home group.Group(simple.RouterPrefix(ctx, consts.AppHome), func(group *ghttp.RouterGroup) { group.Bind( base.Site, // 基础 diff --git a/server/internal/service/admin.go b/server/internal/service/admin.go index 938dbdf..513539b 100644 --- a/server/internal/service/admin.go +++ b/server/internal/service/admin.go @@ -32,6 +32,17 @@ type ( View(ctx context.Context, in adminin.OrderViewInp) (res *adminin.OrderViewModel, err error) Status(ctx context.Context, in adminin.OrderStatusInp) (err error) } + IAdminSite interface { + Register(ctx context.Context, in adminin.RegisterInp) (err error) + AccountLogin(ctx context.Context, in adminin.AccountLoginInp) (res *adminin.LoginModel, err error) + MobileLogin(ctx context.Context, in adminin.MobileLoginInp) (res *adminin.LoginModel, err error) + } + IAdminCash interface { + View(ctx context.Context, in adminin.CashViewInp) (res *adminin.CashViewModel, err error) + List(ctx context.Context, in adminin.CashListInp) (list []*adminin.CashListModel, totalCount int, err error) + Apply(ctx context.Context, in adminin.CashApplyInp) (err error) + Payment(ctx context.Context, in adminin.CashPaymentInp) (err error) + } IAdminDept interface { Delete(ctx context.Context, in adminin.DeptDeleteInp) (err error) Edit(ctx context.Context, in adminin.DeptEditInp) (err error) @@ -42,6 +53,54 @@ type ( List(ctx context.Context, in adminin.DeptListInp) (res *adminin.DeptListModel, err error) GetName(ctx context.Context, id int64) (name string, err error) } + IAdminMonitor interface { + StartMonitor(ctx context.Context) + GetMeta(ctx context.Context) *model.MonitorData + } + IAdminNotice interface { + Model(ctx context.Context, option ...*handler.Option) *gdb.Model + Delete(ctx context.Context, in adminin.NoticeDeleteInp) (err error) + Edit(ctx context.Context, in adminin.NoticeEditInp) (err error) + Status(ctx context.Context, in adminin.NoticeStatusInp) (err error) + MaxSort(ctx context.Context, in adminin.NoticeMaxSortInp) (res *adminin.NoticeMaxSortModel, err error) + View(ctx context.Context, in adminin.NoticeViewInp) (res *adminin.NoticeViewModel, err error) + List(ctx context.Context, in adminin.NoticeListInp) (list []*adminin.NoticeListModel, totalCount int, err error) + PullMessages(ctx context.Context, in adminin.PullMessagesInp) (res *adminin.PullMessagesModel, err error) + UnreadCount(ctx context.Context, in adminin.NoticeUnreadCountInp) (res *adminin.NoticeUnreadCountModel, err error) + UpRead(ctx context.Context, in adminin.NoticeUpReadInp) (err error) + ReadAll(ctx context.Context, in adminin.NoticeReadAllInp) (err error) + MessageList(ctx context.Context, in adminin.NoticeMessageListInp) (list []*adminin.NoticeMessageListModel, totalCount int, err error) + } + IAdminPost interface { + Delete(ctx context.Context, in adminin.PostDeleteInp) (err error) + Edit(ctx context.Context, in adminin.PostEditInp) (err error) + MaxSort(ctx context.Context, in adminin.PostMaxSortInp) (res *adminin.PostMaxSortModel, err error) + NameUnique(ctx context.Context, in adminin.PostNameUniqueInp) (res *adminin.PostNameUniqueModel, err error) + CodeUnique(ctx context.Context, in adminin.PostCodeUniqueInp) (res *adminin.PostCodeUniqueModel, err error) + View(ctx context.Context, in adminin.PostViewInp) (res *adminin.PostViewModel, err error) + List(ctx context.Context, in adminin.PostListInp) (list []*adminin.PostListModel, totalCount int, err error) + GetMemberByStartName(ctx context.Context, memberId int64) (name string, err error) + Status(ctx context.Context, in adminin.PostStatusInp) (err error) + } + IAdminRole interface { + Verify(ctx context.Context, path, method string) bool + List(ctx context.Context, in adminin.RoleListInp) (res *adminin.RoleListModel, totalCount int, err error) + GetName(ctx context.Context, id int64) (name string, err error) + GetMemberList(ctx context.Context, id int64) (list []*adminin.RoleListModel, err error) + GetPermissions(ctx context.Context, in adminin.GetPermissionsInp) (res *adminin.GetPermissionsModel, err error) + UpdatePermissions(ctx context.Context, in adminin.UpdatePermissionsInp) (err error) + Edit(ctx context.Context, in adminin.RoleEditInp) (err error) + Delete(ctx context.Context, in adminin.RoleDeleteInp) (err error) + DataScopeSelect() (res form.Selects) + DataScopeEdit(ctx context.Context, in *adminin.DataScopeEditInp) (err error) + } + IAdminCreditsLog interface { + Model(ctx context.Context, option ...*handler.Option) *gdb.Model + SaveBalance(ctx context.Context, in adminin.CreditsLogSaveBalanceInp) (res *adminin.CreditsLogSaveBalanceModel, err error) + SaveIntegral(ctx context.Context, in adminin.CreditsLogSaveIntegralInp) (res *adminin.CreditsLogSaveIntegralModel, err error) + List(ctx context.Context, in adminin.CreditsLogListInp) (list []*adminin.CreditsLogListModel, totalCount int, err error) + Export(ctx context.Context, in adminin.CreditsLogListInp) (err error) + } IAdminMember interface { AddBalance(ctx context.Context, in adminin.MemberAddBalanceInp) (err error) AddIntegral(ctx context.Context, in adminin.MemberAddIntegralInp) (err error) @@ -68,51 +127,6 @@ type ( IAdminMemberPost interface { UpdatePostIds(ctx context.Context, memberId int64, postIds []int64) (err error) } - IAdminMonitor interface { - StartMonitor(ctx context.Context) - GetMeta(ctx context.Context) *model.MonitorData - } - IAdminPost interface { - Delete(ctx context.Context, in adminin.PostDeleteInp) (err error) - Edit(ctx context.Context, in adminin.PostEditInp) (err error) - MaxSort(ctx context.Context, in adminin.PostMaxSortInp) (res *adminin.PostMaxSortModel, err error) - NameUnique(ctx context.Context, in adminin.PostNameUniqueInp) (res *adminin.PostNameUniqueModel, err error) - CodeUnique(ctx context.Context, in adminin.PostCodeUniqueInp) (res *adminin.PostCodeUniqueModel, err error) - View(ctx context.Context, in adminin.PostViewInp) (res *adminin.PostViewModel, err error) - List(ctx context.Context, in adminin.PostListInp) (list []*adminin.PostListModel, totalCount int, err error) - GetMemberByStartName(ctx context.Context, memberId int64) (name string, err error) - Status(ctx context.Context, in adminin.PostStatusInp) (err error) - } - IAdminRole interface { - Verify(ctx context.Context, path, method string) bool - List(ctx context.Context, in adminin.RoleListInp) (res *adminin.RoleListModel, totalCount int, err error) - GetName(ctx context.Context, id int64) (name string, err error) - GetMemberList(ctx context.Context, id int64) (list []*adminin.RoleListModel, err error) - GetPermissions(ctx context.Context, in adminin.GetPermissionsInp) (res *adminin.GetPermissionsModel, err error) - UpdatePermissions(ctx context.Context, in adminin.UpdatePermissionsInp) (err error) - Edit(ctx context.Context, in adminin.RoleEditInp) (err error) - Delete(ctx context.Context, in adminin.RoleDeleteInp) (err error) - DataScopeSelect() (res form.Selects) - DataScopeEdit(ctx context.Context, in *adminin.DataScopeEditInp) (err error) - } - IAdminSite interface { - Register(ctx context.Context, in adminin.RegisterInp) (err error) - AccountLogin(ctx context.Context, in adminin.AccountLoginInp) (res *adminin.LoginModel, err error) - MobileLogin(ctx context.Context, in adminin.MobileLoginInp) (res *adminin.LoginModel, err error) - } - IAdminCash interface { - View(ctx context.Context, in adminin.CashViewInp) (res *adminin.CashViewModel, err error) - List(ctx context.Context, in adminin.CashListInp) (list []*adminin.CashListModel, totalCount int, err error) - Apply(ctx context.Context, in adminin.CashApplyInp) (err error) - Payment(ctx context.Context, in adminin.CashPaymentInp) (err error) - } - IAdminCreditsLog interface { - Model(ctx context.Context, option ...*handler.Option) *gdb.Model - SaveBalance(ctx context.Context, in adminin.CreditsLogSaveBalanceInp) (res *adminin.CreditsLogSaveBalanceModel, err error) - SaveIntegral(ctx context.Context, in adminin.CreditsLogSaveIntegralInp) (res *adminin.CreditsLogSaveIntegralModel, err error) - List(ctx context.Context, in adminin.CreditsLogListInp) (list []*adminin.CreditsLogListModel, totalCount int, err error) - Export(ctx context.Context, in adminin.CreditsLogListInp) (err error) - } IAdminMenu interface { MaxSort(ctx context.Context, req *menu.MaxSortReq) (res *menu.MaxSortRes, err error) NameUnique(ctx context.Context, req *menu.NameUniqueReq) (res *menu.NameUniqueRes, err error) @@ -124,46 +138,32 @@ type ( GetMenuList(ctx context.Context, memberId int64) (res *role.DynamicRes, err error) LoginPermissions(ctx context.Context, memberId int64) (lists adminin.MemberLoginPermissions, err error) } - IAdminNotice interface { - Model(ctx context.Context, option ...*handler.Option) *gdb.Model - Delete(ctx context.Context, in adminin.NoticeDeleteInp) (err error) - Edit(ctx context.Context, in adminin.NoticeEditInp) (err error) - Status(ctx context.Context, in adminin.NoticeStatusInp) (err error) - MaxSort(ctx context.Context, in adminin.NoticeMaxSortInp) (res *adminin.NoticeMaxSortModel, err error) - View(ctx context.Context, in adminin.NoticeViewInp) (res *adminin.NoticeViewModel, err error) - List(ctx context.Context, in adminin.NoticeListInp) (list []*adminin.NoticeListModel, totalCount int, err error) - PullMessages(ctx context.Context, in adminin.PullMessagesInp) (res *adminin.PullMessagesModel, err error) - UnreadCount(ctx context.Context, in adminin.NoticeUnreadCountInp) (res *adminin.NoticeUnreadCountModel, err error) - UpRead(ctx context.Context, in adminin.NoticeUpReadInp) (err error) - ReadAll(ctx context.Context, in adminin.NoticeReadAllInp) (err error) - MessageList(ctx context.Context, in adminin.NoticeMessageListInp) (list []*adminin.NoticeMessageListModel, totalCount int, err error) - } ) var ( - localAdminCash IAdminCash localAdminCreditsLog IAdminCreditsLog - localAdminMenu IAdminMenu - localAdminNotice IAdminNotice - localAdminPost IAdminPost - localAdminRole IAdminRole - localAdminSite IAdminSite - localAdminDept IAdminDept localAdminMember IAdminMember localAdminMemberPost IAdminMemberPost + localAdminMenu IAdminMenu + localAdminPost IAdminPost + localAdminRole IAdminRole + localAdminCash IAdminCash + localAdminDept IAdminDept localAdminMonitor IAdminMonitor + localAdminNotice IAdminNotice localAdminOrder IAdminOrder + localAdminSite IAdminSite ) -func AdminDept() IAdminDept { - if localAdminDept == nil { - panic("implement not found for interface IAdminDept, forgot register?") +func AdminCreditsLog() IAdminCreditsLog { + if localAdminCreditsLog == nil { + panic("implement not found for interface IAdminCreditsLog, forgot register?") } - return localAdminDept + return localAdminCreditsLog } -func RegisterAdminDept(i IAdminDept) { - localAdminDept = i +func RegisterAdminCreditsLog(i IAdminCreditsLog) { + localAdminCreditsLog = i } func AdminMember() IAdminMember { @@ -188,50 +188,6 @@ func RegisterAdminMemberPost(i IAdminMemberPost) { localAdminMemberPost = i } -func AdminMonitor() IAdminMonitor { - if localAdminMonitor == nil { - panic("implement not found for interface IAdminMonitor, forgot register?") - } - return localAdminMonitor -} - -func RegisterAdminMonitor(i IAdminMonitor) { - localAdminMonitor = i -} - -func AdminOrder() IAdminOrder { - if localAdminOrder == nil { - panic("implement not found for interface IAdminOrder, forgot register?") - } - return localAdminOrder -} - -func RegisterAdminOrder(i IAdminOrder) { - localAdminOrder = i -} - -func AdminCash() IAdminCash { - if localAdminCash == nil { - panic("implement not found for interface IAdminCash, forgot register?") - } - return localAdminCash -} - -func RegisterAdminCash(i IAdminCash) { - localAdminCash = i -} - -func AdminCreditsLog() IAdminCreditsLog { - if localAdminCreditsLog == nil { - panic("implement not found for interface IAdminCreditsLog, forgot register?") - } - return localAdminCreditsLog -} - -func RegisterAdminCreditsLog(i IAdminCreditsLog) { - localAdminCreditsLog = i -} - func AdminMenu() IAdminMenu { if localAdminMenu == nil { panic("implement not found for interface IAdminMenu, forgot register?") @@ -243,17 +199,6 @@ func RegisterAdminMenu(i IAdminMenu) { localAdminMenu = i } -func AdminNotice() IAdminNotice { - if localAdminNotice == nil { - panic("implement not found for interface IAdminNotice, forgot register?") - } - return localAdminNotice -} - -func RegisterAdminNotice(i IAdminNotice) { - localAdminNotice = i -} - func AdminPost() IAdminPost { if localAdminPost == nil { panic("implement not found for interface IAdminPost, forgot register?") @@ -276,6 +221,61 @@ func RegisterAdminRole(i IAdminRole) { localAdminRole = i } +func AdminCash() IAdminCash { + if localAdminCash == nil { + panic("implement not found for interface IAdminCash, forgot register?") + } + return localAdminCash +} + +func RegisterAdminCash(i IAdminCash) { + localAdminCash = i +} + +func AdminDept() IAdminDept { + if localAdminDept == nil { + panic("implement not found for interface IAdminDept, forgot register?") + } + return localAdminDept +} + +func RegisterAdminDept(i IAdminDept) { + localAdminDept = i +} + +func AdminMonitor() IAdminMonitor { + if localAdminMonitor == nil { + panic("implement not found for interface IAdminMonitor, forgot register?") + } + return localAdminMonitor +} + +func RegisterAdminMonitor(i IAdminMonitor) { + localAdminMonitor = i +} + +func AdminNotice() IAdminNotice { + if localAdminNotice == nil { + panic("implement not found for interface IAdminNotice, forgot register?") + } + return localAdminNotice +} + +func RegisterAdminNotice(i IAdminNotice) { + localAdminNotice = i +} + +func AdminOrder() IAdminOrder { + if localAdminOrder == nil { + panic("implement not found for interface IAdminOrder, forgot register?") + } + return localAdminOrder +} + +func RegisterAdminOrder(i IAdminOrder) { + localAdminOrder = i +} + func AdminSite() IAdminSite { if localAdminSite == nil { panic("implement not found for interface IAdminSite, forgot register?") diff --git a/server/internal/service/middleware.go b/server/internal/service/middleware.go index 3665ff1..e739453 100644 --- a/server/internal/service/middleware.go +++ b/server/internal/service/middleware.go @@ -15,6 +15,7 @@ type ( IMiddleware interface { AdminAuth(r *ghttp.Request) ApiAuth(r *ghttp.Request) + HomeAuth(r *ghttp.Request) Ctx(r *ghttp.Request) CORS(r *ghttp.Request) DemoLimit(r *ghttp.Request) diff --git a/server/internal/service/sys.go b/server/internal/service/sys.go index 4bf7f27..c9e43da 100644 --- a/server/internal/service/sys.go +++ b/server/internal/service/sys.go @@ -29,11 +29,58 @@ type ( UniqueId(ctx context.Context, in sysin.ProvincesUniqueIdInp) (res *sysin.ProvincesUniqueIdModel, err error) Select(ctx context.Context, in sysin.ProvincesSelectInp) (res *sysin.ProvincesSelectModel, err error) } - ISysAttachment interface { - Model(ctx context.Context, option ...*handler.Option) *gdb.Model - Delete(ctx context.Context, in sysin.AttachmentDeleteInp) (err error) - View(ctx context.Context, in sysin.AttachmentViewInp) (res *sysin.AttachmentViewModel, err error) - List(ctx context.Context, in sysin.AttachmentListInp) (list []*sysin.AttachmentListModel, totalCount int, err error) + ISysSmsLog interface { + Delete(ctx context.Context, in sysin.SmsLogDeleteInp) (err error) + Edit(ctx context.Context, in sysin.SmsLogEditInp) (err error) + Status(ctx context.Context, in sysin.SmsLogStatusInp) (err error) + MaxSort(ctx context.Context, in sysin.SmsLogMaxSortInp) (res *sysin.SmsLogMaxSortModel, err error) + View(ctx context.Context, in sysin.SmsLogViewInp) (res *sysin.SmsLogViewModel, err error) + List(ctx context.Context, in sysin.SmsLogListInp) (list []*sysin.SmsLogListModel, totalCount int, err error) + SendCode(ctx context.Context, in sysin.SendCodeInp) (err error) + GetTemplate(ctx context.Context, template string, config *model.SmsConfig) (val string, err error) + AllowSend(ctx context.Context, models *entity.SysSmsLog, config *model.SmsConfig) (err error) + VerifyCode(ctx context.Context, in sysin.VerifyCodeInp) (err error) + } + ISysAddons interface { + List(ctx context.Context, in sysin.AddonsListInp) (list []*sysin.AddonsListModel, totalCount int, err error) + Selects(ctx context.Context, in sysin.AddonsSelectsInp) (res *sysin.AddonsSelectsModel, err error) + Build(ctx context.Context, in sysin.AddonsBuildInp) (err error) + Install(ctx context.Context, in sysin.AddonsInstallInp) (err error) + Upgrade(ctx context.Context, in sysin.AddonsUpgradeInp) (err error) + UnInstall(ctx context.Context, in sysin.AddonsUnInstallInp) (err error) + } + ISysLoginLog interface { + Model(ctx context.Context) *gdb.Model + List(ctx context.Context, in sysin.LoginLogListInp) (list []*sysin.LoginLogListModel, totalCount int, err error) + Export(ctx context.Context, in sysin.LoginLogListInp) (err error) + Delete(ctx context.Context, in sysin.LoginLogDeleteInp) (err error) + View(ctx context.Context, in sysin.LoginLogViewInp) (res *sysin.LoginLogViewModel, err error) + Push(ctx context.Context, in sysin.LoginLogPushInp) + RealWrite(ctx context.Context, models entity.SysLoginLog) (err error) + } + ISysLog interface { + Export(ctx context.Context, in sysin.LogListInp) (err error) + RealWrite(ctx context.Context, log entity.SysLog) (err error) + AutoLog(ctx context.Context) error + AnalysisLog(ctx context.Context) entity.SysLog + View(ctx context.Context, in sysin.LogViewInp) (res *sysin.LogViewModel, err error) + Delete(ctx context.Context, in sysin.LogDeleteInp) (err error) + List(ctx context.Context, in sysin.LogListInp) (list []*sysin.LogListModel, totalCount int, err error) + } + ISysCronGroup interface { + Delete(ctx context.Context, in sysin.CronGroupDeleteInp) (err error) + Edit(ctx context.Context, in sysin.CronGroupEditInp) (err error) + Status(ctx context.Context, in sysin.CronGroupStatusInp) (err error) + MaxSort(ctx context.Context, in sysin.CronGroupMaxSortInp) (res *sysin.CronGroupMaxSortModel, err error) + View(ctx context.Context, in sysin.CronGroupViewInp) (res *sysin.CronGroupViewModel, err error) + List(ctx context.Context, in sysin.CronGroupListInp) (list []*sysin.CronGroupListModel, totalCount int, err error) + Select(ctx context.Context, in sysin.CronGroupSelectInp) (res *sysin.CronGroupSelectModel, err error) + } + ISysDictData interface { + Delete(ctx context.Context, in sysin.DictDataDeleteInp) error + Edit(ctx context.Context, in sysin.DictDataEditInp) (err error) + List(ctx context.Context, in sysin.DictDataListInp) (list []*sysin.DictDataListModel, totalCount int, err error) + Select(ctx context.Context, in sysin.DataSelectInp) (list sysin.DataSelectModel, err error) } ISysCron interface { StartCron(ctx context.Context) @@ -45,15 +92,6 @@ type ( List(ctx context.Context, in sysin.CronListInp) (list []*sysin.CronListModel, totalCount int, err error) OnlineExec(ctx context.Context, in sysin.OnlineExecInp) (err error) } - ISysCronGroup interface { - Delete(ctx context.Context, in sysin.CronGroupDeleteInp) (err error) - Edit(ctx context.Context, in sysin.CronGroupEditInp) (err error) - Status(ctx context.Context, in sysin.CronGroupStatusInp) (err error) - MaxSort(ctx context.Context, in sysin.CronGroupMaxSortInp) (res *sysin.CronGroupMaxSortModel, err error) - View(ctx context.Context, in sysin.CronGroupViewInp) (res *sysin.CronGroupViewModel, err error) - List(ctx context.Context, in sysin.CronGroupListInp) (list []*sysin.CronGroupListModel, totalCount int, err error) - Select(ctx context.Context, in sysin.CronGroupSelectInp) (res *sysin.CronGroupSelectModel, err error) - } ISysGenCodes interface { Delete(ctx context.Context, in sysin.GenCodesDeleteInp) (err error) Edit(ctx context.Context, in sysin.GenCodesEditInp) (res *sysin.GenCodesEditModel, err error) @@ -83,32 +121,6 @@ type ( VariableLoad(ctx context.Context, err error) Load(ctx context.Context) } - ISysLoginLog interface { - Model(ctx context.Context) *gdb.Model - List(ctx context.Context, in sysin.LoginLogListInp) (list []*sysin.LoginLogListModel, totalCount int, err error) - Export(ctx context.Context, in sysin.LoginLogListInp) (err error) - Delete(ctx context.Context, in sysin.LoginLogDeleteInp) (err error) - View(ctx context.Context, in sysin.LoginLogViewInp) (res *sysin.LoginLogViewModel, err error) - Push(ctx context.Context, in sysin.LoginLogPushInp) - RealWrite(ctx context.Context, models entity.SysLoginLog) (err error) - } - ISysDictData interface { - Delete(ctx context.Context, in sysin.DictDataDeleteInp) error - Edit(ctx context.Context, in sysin.DictDataEditInp) (err error) - List(ctx context.Context, in sysin.DictDataListInp) (list []*sysin.DictDataListModel, totalCount int, err error) - Select(ctx context.Context, in sysin.DataSelectInp) (list sysin.DataSelectModel, err error) - } - ISysEmsLog interface { - Delete(ctx context.Context, in sysin.EmsLogDeleteInp) (err error) - Edit(ctx context.Context, in sysin.EmsLogEditInp) (err error) - Status(ctx context.Context, in sysin.EmsLogStatusInp) (err error) - View(ctx context.Context, in sysin.EmsLogViewInp) (res *sysin.EmsLogViewModel, err error) - List(ctx context.Context, in sysin.EmsLogListInp) (list []*sysin.EmsLogListModel, totalCount int, err error) - Send(ctx context.Context, in sysin.SendEmsInp) (err error) - GetTemplate(ctx context.Context, template string, config *model.EmailConfig) (val string, err error) - AllowSend(ctx context.Context, models *entity.SysEmsLog, config *model.EmailConfig) (err error) - VerifyCode(ctx context.Context, in sysin.VerifyEmsCodeInp) (err error) - } ISysCurdDemo interface { Model(ctx context.Context, option ...*handler.Option) *gdb.Model List(ctx context.Context, in sysin.CurdDemoListInp) (list []*sysin.CurdDemoListModel, totalCount int, err error) @@ -126,14 +138,16 @@ type ( Edit(ctx context.Context, in sysin.DictTypeEditInp) (err error) TreeSelect(ctx context.Context, in sysin.DictTreeSelectInp) (list []*sysin.DictTypeTree, err error) } - ISysLog interface { - Export(ctx context.Context, in sysin.LogListInp) (err error) - RealWrite(ctx context.Context, log entity.SysLog) (err error) - AutoLog(ctx context.Context) error - AnalysisLog(ctx context.Context) entity.SysLog - View(ctx context.Context, in sysin.LogViewInp) (res *sysin.LogViewModel, err error) - Delete(ctx context.Context, in sysin.LogDeleteInp) (err error) - List(ctx context.Context, in sysin.LogListInp) (list []*sysin.LogListModel, totalCount int, err error) + ISysEmsLog interface { + Delete(ctx context.Context, in sysin.EmsLogDeleteInp) (err error) + Edit(ctx context.Context, in sysin.EmsLogEditInp) (err error) + Status(ctx context.Context, in sysin.EmsLogStatusInp) (err error) + View(ctx context.Context, in sysin.EmsLogViewInp) (res *sysin.EmsLogViewModel, err error) + List(ctx context.Context, in sysin.EmsLogListInp) (list []*sysin.EmsLogListModel, totalCount int, err error) + Send(ctx context.Context, in sysin.SendEmsInp) (err error) + GetTemplate(ctx context.Context, template string, config *model.EmailConfig) (val string, err error) + AllowSend(ctx context.Context, models *entity.SysEmsLog, config *model.EmailConfig) (err error) + VerifyCode(ctx context.Context, in sysin.VerifyEmsCodeInp) (err error) } ISysServeLog interface { Model(ctx context.Context) *gdb.Model @@ -143,25 +157,11 @@ type ( View(ctx context.Context, in sysin.ServeLogViewInp) (res *sysin.ServeLogViewModel, err error) RealWrite(ctx context.Context, models entity.SysServeLog) (err error) } - ISysSmsLog interface { - Delete(ctx context.Context, in sysin.SmsLogDeleteInp) (err error) - Edit(ctx context.Context, in sysin.SmsLogEditInp) (err error) - Status(ctx context.Context, in sysin.SmsLogStatusInp) (err error) - MaxSort(ctx context.Context, in sysin.SmsLogMaxSortInp) (res *sysin.SmsLogMaxSortModel, err error) - View(ctx context.Context, in sysin.SmsLogViewInp) (res *sysin.SmsLogViewModel, err error) - List(ctx context.Context, in sysin.SmsLogListInp) (list []*sysin.SmsLogListModel, totalCount int, err error) - SendCode(ctx context.Context, in sysin.SendCodeInp) (err error) - GetTemplate(ctx context.Context, template string, config *model.SmsConfig) (val string, err error) - AllowSend(ctx context.Context, models *entity.SysSmsLog, config *model.SmsConfig) (err error) - VerifyCode(ctx context.Context, in sysin.VerifyCodeInp) (err error) - } - ISysAddons interface { - List(ctx context.Context, in sysin.AddonsListInp) (list []*sysin.AddonsListModel, totalCount int, err error) - Selects(ctx context.Context, in sysin.AddonsSelectsInp) (res *sysin.AddonsSelectsModel, err error) - Build(ctx context.Context, in sysin.AddonsBuildInp) (err error) - Install(ctx context.Context, in sysin.AddonsInstallInp) (err error) - Upgrade(ctx context.Context, in sysin.AddonsUpgradeInp) (err error) - UnInstall(ctx context.Context, in sysin.AddonsUnInstallInp) (err error) + ISysAttachment interface { + Model(ctx context.Context, option ...*handler.Option) *gdb.Model + Delete(ctx context.Context, in sysin.AttachmentDeleteInp) (err error) + View(ctx context.Context, in sysin.AttachmentViewInp) (res *sysin.AttachmentViewModel, err error) + List(ctx context.Context, in sysin.AttachmentListInp) (list []*sysin.AttachmentListModel, totalCount int, err error) } ISysConfig interface { InitConfig(ctx context.Context) @@ -186,23 +186,23 @@ type ( ) var ( - localSysBlacklist ISysBlacklist - localSysCronGroup ISysCronGroup - localSysGenCodes ISysGenCodes - localSysAddonsConfig ISysAddonsConfig - localSysEmsLog ISysEmsLog + localSysAddons ISysAddons localSysLoginLog ISysLoginLog + localSysProvinces ISysProvinces + localSysSmsLog ISysSmsLog + localSysCronGroup ISysCronGroup localSysDictData ISysDictData + localSysLog ISysLog + localSysAddonsConfig ISysAddonsConfig + localSysBlacklist ISysBlacklist + localSysCron ISysCron + localSysGenCodes ISysGenCodes + localSysAttachment ISysAttachment localSysConfig ISysConfig localSysCurdDemo ISysCurdDemo localSysDictType ISysDictType - localSysLog ISysLog + localSysEmsLog ISysEmsLog localSysServeLog ISysServeLog - localSysSmsLog ISysSmsLog - localSysAddons ISysAddons - localSysCron ISysCron - localSysProvinces ISysProvinces - localSysAttachment ISysAttachment ) func SysBlacklist() ISysBlacklist { @@ -216,15 +216,15 @@ func RegisterSysBlacklist(i ISysBlacklist) { localSysBlacklist = i } -func SysCronGroup() ISysCronGroup { - if localSysCronGroup == nil { - panic("implement not found for interface ISysCronGroup, forgot register?") +func SysCron() ISysCron { + if localSysCron == nil { + panic("implement not found for interface ISysCron, forgot register?") } - return localSysCronGroup + return localSysCron } -func RegisterSysCronGroup(i ISysCronGroup) { - localSysCronGroup = i +func RegisterSysCron(i ISysCron) { + localSysCron = i } func SysGenCodes() ISysGenCodes { @@ -249,39 +249,6 @@ func RegisterSysAddonsConfig(i ISysAddonsConfig) { localSysAddonsConfig = i } -func SysEmsLog() ISysEmsLog { - if localSysEmsLog == nil { - panic("implement not found for interface ISysEmsLog, forgot register?") - } - return localSysEmsLog -} - -func RegisterSysEmsLog(i ISysEmsLog) { - localSysEmsLog = i -} - -func SysLoginLog() ISysLoginLog { - if localSysLoginLog == nil { - panic("implement not found for interface ISysLoginLog, forgot register?") - } - return localSysLoginLog -} - -func RegisterSysLoginLog(i ISysLoginLog) { - localSysLoginLog = i -} - -func SysDictData() ISysDictData { - if localSysDictData == nil { - panic("implement not found for interface ISysDictData, forgot register?") - } - return localSysDictData -} - -func RegisterSysDictData(i ISysDictData) { - localSysDictData = i -} - func SysConfig() ISysConfig { if localSysConfig == nil { panic("implement not found for interface ISysConfig, forgot register?") @@ -315,15 +282,15 @@ func RegisterSysDictType(i ISysDictType) { localSysDictType = i } -func SysLog() ISysLog { - if localSysLog == nil { - panic("implement not found for interface ISysLog, forgot register?") +func SysEmsLog() ISysEmsLog { + if localSysEmsLog == nil { + panic("implement not found for interface ISysEmsLog, forgot register?") } - return localSysLog + return localSysEmsLog } -func RegisterSysLog(i ISysLog) { - localSysLog = i +func RegisterSysEmsLog(i ISysEmsLog) { + localSysEmsLog = i } func SysServeLog() ISysServeLog { @@ -337,6 +304,39 @@ func RegisterSysServeLog(i ISysServeLog) { localSysServeLog = i } +func SysAttachment() ISysAttachment { + if localSysAttachment == nil { + panic("implement not found for interface ISysAttachment, forgot register?") + } + return localSysAttachment +} + +func RegisterSysAttachment(i ISysAttachment) { + localSysAttachment = i +} + +func SysLoginLog() ISysLoginLog { + if localSysLoginLog == nil { + panic("implement not found for interface ISysLoginLog, forgot register?") + } + return localSysLoginLog +} + +func RegisterSysLoginLog(i ISysLoginLog) { + localSysLoginLog = i +} + +func SysProvinces() ISysProvinces { + if localSysProvinces == nil { + panic("implement not found for interface ISysProvinces, forgot register?") + } + return localSysProvinces +} + +func RegisterSysProvinces(i ISysProvinces) { + localSysProvinces = i +} + func SysSmsLog() ISysSmsLog { if localSysSmsLog == nil { panic("implement not found for interface ISysSmsLog, forgot register?") @@ -359,35 +359,35 @@ func RegisterSysAddons(i ISysAddons) { localSysAddons = i } -func SysCron() ISysCron { - if localSysCron == nil { - panic("implement not found for interface ISysCron, forgot register?") +func SysDictData() ISysDictData { + if localSysDictData == nil { + panic("implement not found for interface ISysDictData, forgot register?") } - return localSysCron + return localSysDictData } -func RegisterSysCron(i ISysCron) { - localSysCron = i +func RegisterSysDictData(i ISysDictData) { + localSysDictData = i } -func SysProvinces() ISysProvinces { - if localSysProvinces == nil { - panic("implement not found for interface ISysProvinces, forgot register?") +func SysLog() ISysLog { + if localSysLog == nil { + panic("implement not found for interface ISysLog, forgot register?") } - return localSysProvinces + return localSysLog } -func RegisterSysProvinces(i ISysProvinces) { - localSysProvinces = i +func RegisterSysLog(i ISysLog) { + localSysLog = i } -func SysAttachment() ISysAttachment { - if localSysAttachment == nil { - panic("implement not found for interface ISysAttachment, forgot register?") +func SysCronGroup() ISysCronGroup { + if localSysCronGroup == nil { + panic("implement not found for interface ISysCronGroup, forgot register?") } - return localSysAttachment + return localSysCronGroup } -func RegisterSysAttachment(i ISysAttachment) { - localSysAttachment = i +func RegisterSysCronGroup(i ISysCronGroup) { + localSysCronGroup = i } diff --git a/server/internal/service/tcpclient.go b/server/internal/service/tcpclient.go index 895b521..f9bb607 100644 --- a/server/internal/service/tcpclient.go +++ b/server/internal/service/tcpclient.go @@ -10,6 +10,12 @@ import ( ) type ( + IAuthClient interface { + Start(ctx context.Context) + Stop(ctx context.Context) + IsLogin() bool + OnResponseAuthSummary(ctx context.Context, args ...interface{}) + } ICronClient interface { Start(ctx context.Context) Stop(ctx context.Context) @@ -19,12 +25,6 @@ type ( OnCronStatus(ctx context.Context, args ...interface{}) OnCronOnlineExec(ctx context.Context, args ...interface{}) } - IAuthClient interface { - Start(ctx context.Context) - Stop(ctx context.Context) - IsLogin() bool - OnResponseAuthSummary(ctx context.Context, args ...interface{}) - } ) var ( diff --git a/server/internal/service/view.go b/server/internal/service/view.go index a757343..84a3124 100644 --- a/server/internal/service/view.go +++ b/server/internal/service/view.go @@ -16,11 +16,6 @@ type ( GetTitle(ctx context.Context, in *model.ViewGetTitleInput) string RenderTpl(ctx context.Context, tpl string, data ...model.View) Render(ctx context.Context, data ...model.View) - Render302(ctx context.Context, data ...model.View) - Render401(ctx context.Context, data ...model.View) - Render403(ctx context.Context, data ...model.View) - Render404(ctx context.Context, data ...model.View) - Render500(ctx context.Context, data ...model.View) Error(ctx context.Context, err error) } ) diff --git a/server/resource/template/error/default.html b/server/resource/template/error/default.html new file mode 100644 index 0000000..f21f4f2 --- /dev/null +++ b/server/resource/template/error/default.html @@ -0,0 +1,94 @@ + + +
+ + +