This commit is contained in:
孟帅
2022-02-25 17:11:17 +08:00
parent 9bd05abb2c
commit 8f3d679a57
897 changed files with 95731 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
//
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2022 HotGo CLI
// @Author  Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
//
package boot
import (
"context"
"github.com/bufanyun/hotgo/app/consts"
"github.com/bufanyun/hotgo/app/factory/queue"
"github.com/bufanyun/hotgo/app/service/sysService"
)
//
//  @Title  消息队列监听
//  @Description 
//  @Author  Ms <133814250@qq.com>
//  @Param   ctx
//
func QueueListen(ctx context.Context) {
consumer, err := queue.InstanceConsumer()
if err != nil {
queue.FatalLog(ctx, "InstanceConsumer异常", err)
return
}
// 全局日志
if listenErr := consumer.ListenReceiveMsgDo(consts.QueueLogTopic, func(mqMsg queue.MqMsg) {
// 自定义消费回调
err := sysService.Log.QueueJob(ctx, mqMsg)
// 记录消费日志
queue.ConsumerLog(ctx, consts.QueueLogTopic, mqMsg, err)
}); listenErr != nil {
queue.FatalLog(ctx, "主题:"+consts.QueueLogTopic+" 监听失败", listenErr)
}
}

96
hotgo-server/boot/run.go Normal file
View File

@@ -0,0 +1,96 @@
//
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2022 HotGo CLI
// @Author  Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
//
package boot
import (
"context"
"github.com/bufanyun/hotgo/app/consts"
"github.com/bufanyun/hotgo/app/hook"
"github.com/bufanyun/hotgo/app/middleware"
"github.com/bufanyun/hotgo/app/model"
"github.com/bufanyun/hotgo/router"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
"github.com/gogf/gf/v2/os/gcmd"
"github.com/gogf/gf/v2/protocol/goai"
)
var (
Main = gcmd.Command{
Name: "main",
Usage: "main",
Brief: "start http server of HotGo!",
Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
s := g.Server()
// 错误状态码接管
s.BindStatusHandler(404, func(r *ghttp.Request) {
r.Response.Writeln("404 - 你似乎来到了没有知识存在的荒原…")
})
s.BindStatusHandler(403, func(r *ghttp.Request) {
r.Response.Writeln("403 - 网站拒绝显示此网页")
})
// 请求结束事件回调
s.BindHookHandler("/*any", ghttp.HookAfterOutput, hook.Instance().GlobalLog)
s.Group("/", func(group *ghttp.RouterGroup) {
// 注册全局中间件
group.Middleware(
middleware.Instance().Ctx, //必须第一个加载
middleware.Instance().CORS,
middleware.Instance().HandlerResponse,
)
// 注册默认首页路由
group.ALL("/", func(r *ghttp.Request) {
r.Response.Write("hello hotGo!!")
})
// 注册后台路由
router.Admin(ctx, group)
// 注册API路由
router.Api(ctx, group)
})
// Custom enhance API document.
enhanceOpenAPIDoc(s)
// 消息队列
QueueListen(ctx)
// Just run the server.
s.Run()
return nil
},
}
)
//
//  @Title  API document
//  @Description
//  @Author  Ms <133814250@qq.com>
//  @Param   s
//
func enhanceOpenAPIDoc(s *ghttp.Server) {
openapi := s.GetOpenApi()
openapi.Config.CommonResponse = model.Response{}
openapi.Config.CommonResponseDataField = `Data`
// API description.
openapi.Info = goai.Info{
Title: consts.OpenAPITitle,
Description: consts.OpenAPIDescription,
Contact: &goai.Contact{
Name: consts.OpenAPIName,
URL: consts.OpenAPIURL,
},
}
}