cmd

package
v0.0.0-...-52c304b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 23, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Main = gcmd.Command{
		Name:  "main",
		Usage: "main",
		Brief: "start http server",
		Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {

			sigChan := make(chan os.Signal, 1)
			signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)

			go func() {
				sig := <-sigChan
				g.Log().Infof(ctx, "收到关闭信号: %v,开始优雅关闭...", sig)

				g.Log().Info(ctx, "正在刷盘缓存数据...")
				if messageCache := internalCache.GetMessageCache(); messageCache != nil {
					messageCache.Close()
					g.Log().Info(ctx, "✓ 消息缓存层已关闭")
				}
				if mcpLogCache := internalCache.GetMCPCallLogCache(); mcpLogCache != nil {
					mcpLogCache.Close()
					g.Log().Info(ctx, "✓ MCP日志缓存层已关闭")
				}

				g.Log().Info(ctx, "✓ 所有缓存数据已刷盘完成")

				if err := g.Server().Shutdown(); err != nil {
					g.Log().Errorf(ctx, "HTTP服务器关闭失败: %v", err)
				}

				os.Exit(0)
			}()

			s := g.Server()

			s.SetServerRoot(".")
			s.AddStaticPath("/", ".")

			s.Group("/api", func(group *ghttp.RouterGroup) {
				group.Middleware(MiddlewareMultipartMaxMemory, MiddlewareHandlerResponse, ghttp.MiddlewareCORS)
				group.Bind(
					kbgo.NewV1(),
				)
			})
			s.Run()
			return nil
		},
	}
)

Functions

func MiddlewareHandlerResponse

func MiddlewareHandlerResponse(r *ghttp.Request)

MiddlewareHandlerResponse is the default middleware handling handler response object and its error.

func MiddlewareMultipartMaxMemory

func MiddlewareMultipartMaxMemory(r *ghttp.Request)

MiddlewareMultipartMaxMemory 根据不同的路由设置不同的文件上传大小限制

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL