Files
bl/login/internal/cmd/cmd.go
昔念 699231ee38 ```
feat(vscode): 添加调试参数配置

为launch.json添加-debug=1参数,便于调试模式启动

docs(README): 补充zellij终端复用工具使用说明

添加x-cmd安装和zellij会话管理相关命令示例

refactor(config): 注释掉GamePort配置项

暂时注释GamePort配置项以解决配置冲突问题

refactor(xmlres): 移除未使用的gf框架依赖并注释文件监控逻辑

移除未使用的gctx、gfile、gfsnotify、glog导入包
注释init函数中的文件监控逻辑,避免不必要的文件监听
```
2026-01-02 04:11:37 +08:00

74 lines
2.0 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package cmd
import (
"context"
"blazing/cool"
i18n "blazing/modules/base/middleware"
"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/os/gfile"
"golang.org/x/time/rate"
)
var (
Main = gcmd.Command{
Name: "main",
Usage: "main",
Brief: "start http server",
Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
// g.Dump(g.DB("test").GetConfig())
r := parser.GetArgAll()
if len(r) > 1 {
g.DB().SetDebug(true)
}
if cool.IsRedisMode {
go cool.ListenFunc(ctx)
}
//go robot()
go reg()
s := g.Server()
s.Use(Limiter, ghttp.MiddlewareHandlerResponse)
s.EnableAdmin()
s.SetServerAgent(cool.Config.Name)
s.BindHookHandler("/*", ghttp.HookBeforeServe, beforeServeHook)
// runtime.SetMutexProfileFraction(1) // (非必需)开启对锁调用的跟踪
// runtime.SetBlockProfileRate(1) // (非必需)开启对阻塞操作的跟踪
// s.EnablePProf()
// 如果存在 data/cool-admin-vue/dist 目录,则设置为主目录
if gfile.IsDir("public") {
s.SetServerRoot("public")
}
// i18n 信息
s.BindHandler("/i18n", i18n.I18nInfo)
// g.Server().BindMiddleware("/*", MiddlewareCORS)
s.Run()
return nil
},
}
)
func beforeServeHook(r *ghttp.Request) {
//glog.Debugf(r.GetCtx(), "beforeServeHook [is file:%v] URI:%s", r.IsFileRequest(), r.RequestURI)
r.Response.CORSDefault()
}
var limiter = rate.NewLimiter(rate.Limit(10), 5)
// Limiter is a middleware that implements rate limiting for all HTTP requests.
// It returns HTTP 429 (Too Many Requests) when the rate limit is exceeded.
func Limiter(r *ghttp.Request) {
// 3. 为任意键 "some-key" 获取一个速率限制器
// - rate.Limit(2): 表示速率为 "每秒2个请求"
// - 2: 表示桶的容量 (Burst)允许瞬时处理2个请求
if !limiter.Allow() {
r.Response.WriteStatusExit(429) // Return 429 Too Many Requests
r.ExitAll()
}
r.Middleware.Next()
}