1 Star 1 Fork 0

linngc / center.gf

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
hook_after_load.go 3.00 KB
一键复制 编辑 原始数据 按行查看 历史
linngc 提交于 2023-08-02 16:17 . perf:提取指令通用包
// Package hook
// @Link https://gitee.com/linngc/center.gf
// @Copyright Copyright (c) 2022 webos CLI
// @Author linngc
// @License
// @title 服务加载之前
package hook
import (
"context"
"gitee.com/linngc/center.gf/contrib/module/command/utility"
"gitee.com/linngc/center.gf/utility/tools/env"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
"github.com/gogf/gf/v2/net/gipv4"
"github.com/gogf/gf/v2/os/gfile"
)
// bindStatusHandler 前台系统自定义错误页面
func (c *cHook) bindStatusHandler(s *ghttp.Server) {
//s.BindStatusHandler(400, func(r *ghttp.Request) {
// if !gstr.HasPrefix(r.URL.Path, "/400") {
// home.Error.ErrorStatusHtml(r.GetCtx(), &v1.ErrorReq{Status: "400"})
// }
//})
//s.BindStatusHandler(404, func(r *ghttp.Request) {
// if !gstr.HasPrefix(r.URL.Path, "/404") {
// home.Error.ErrorStatusHtml(r.GetCtx(), &v1.ErrorReq{Status: "404"})
// }
//})
//s.BindStatusHandler(500, func(r *ghttp.Request) {
// if !gstr.HasPrefix(r.URL.Path, "/500") {
// home.Error.ErrorStatusHtml(r.GetCtx(), &v1.ErrorReq{Status: "500"})
// }
//})
//s.BindHandler("/error/:status", func(r *ghttp.Request) {
// home.Error.ErrorStatusHtml(r.GetCtx(), &v1.ErrorReq{Status: r.Get("status").String()})
//})
//
//// HOOK, 开发阶段禁止浏览器缓存,方便调试
//if gmode.IsDevelop() {
// s.BindHookHandler("/*", ghttp.HookBeforeServe, func(r *ghttp.Request) {
// r.Response.Header().Set("Cache-Control", "no-store")
// })
//}
}
// consolePrintfHandlers 输出项目启动运行信息
func (c *cHook) consolePrintfHandlers(s *ghttp.Server) {
application := env.GetApplicationName() //启用应用名称
serverPort, _ := env.GetAddress() //服务端口
host, _ := gipv4.GetIntranetIp() //本地id
swaggerPath, _ := env.GetSwaggerPath() //swagger地址
serverPortStr := serverPort.String()
swaggerPathStr := swaggerPath.String() //swagger访问地址
//
g.Log().Infof(context.TODO(),
"\n------------------------------------------应用服务信息----------------------------------------------\n\t"+
"Application '%s' is running! Access URLs:\n\t"+
"Local: \t\t\t\t http://localhost:%s\n\t"+
"External: \t\t\t http://%s:%s\n\t"+
"Websocket: \t\t\t http://%s:%s\n\t"+
"Doc: \t\t\t\t http://%s:%s/%s/doc.html\n"+
"-----------------------------------------------------------------------------------------------------\n",
application,
serverPortStr,
host, serverPortStr,
host, serverPortStr,
host, serverPortStr, swaggerPathStr)
//如启动模式为dev则打印程序版本信息
if env.IsDev() {
versionStr := utility.GetVersionStr() //系统版本信息
g.Log().Infof(context.TODO(), "\n-----------------------------------------------------------------------------------------------------\n"+
"%s"+
"\n-----------------------------------------------------------------------------------------------------\n", versionStr)
} else {
g.Log().Infof(context.TODO(), gfile.GetContents(gfile.Pwd()+"/resource/public/html/bannar.txt"))
}
}
Go
1
https://gitee.com/linngc/center.gf.git
git@gitee.com:linngc/center.gf.git
linngc
center.gf
center.gf
v0.2.12

搜索帮助