hotgo/server/internal/cmd/cmd.go

88 lines
2.3 KiB
Go
Raw Normal View History

2022-11-24 23:37:34 +08:00
// Package cmd
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
2022-11-24 23:37:34 +08:00
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
//
package cmd
import (
"context"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gcmd"
2022-11-25 23:22:44 +08:00
"hotgo/utility/simple"
2022-11-24 23:37:34 +08:00
)
var (
serverCloseSignal chan struct{}
Main = &gcmd.Command{
Description: `默认启动所有服务`,
Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
return All.Func(ctx, parser)
},
}
Help = &gcmd.Command{
Name: "help",
Brief: "查看帮助",
2022-11-24 23:37:34 +08:00
Description: `
命令提示符
2022-11-24 23:37:34 +08:00
---------------------------------------------------------------------------------
启动服务
>> 所有服务 [go run main.go] 热编译 [gf run main.go]
2022-11-25 23:22:44 +08:00
>> HTTP服务 [go run main.go http]
>> 消息队列 [go run main.go queue]
>> 查看帮助 [go run main.go help]
2022-11-24 23:37:34 +08:00
---------------------------------------------------------------------------------
工具
2022-11-25 23:22:44 +08:00
>> 释放casbin权限用于清理无效的权限设置 [go run main.go tools -m=casbin -a1=refresh]
2022-11-24 23:37:34 +08:00
---------------------------------------------------------------------------------
更多
github地址https://github.com/bufanyun/hotgo
文档地址https://github.com/bufanyun/hotgo/tree/v2.0/docs/guide-zh-CN
HotGo框架交流1群190966648
2022-11-24 23:37:34 +08:00
`,
}
All = &gcmd.Command{
Name: "all",
Brief: "start all server",
Description: "this is the command entry for starting all server",
Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
g.Log().Debug(ctx, "starting all server")
2022-11-24 23:37:34 +08:00
2022-11-25 23:22:44 +08:00
simple.SafeGo(ctx, func(ctx context.Context) {
2023-02-08 20:29:34 +08:00
if err := Queue.Func(ctx, parser); err != nil {
g.Log().Fatal(ctx, "queue consumer start fail:", err)
2022-11-24 23:37:34 +08:00
}
2022-11-25 23:22:44 +08:00
})
2022-11-24 23:37:34 +08:00
2022-11-25 23:22:44 +08:00
simple.SafeGo(ctx, func(ctx context.Context) {
2023-02-08 20:29:34 +08:00
if err := Http.Func(ctx, parser); err != nil {
g.Log().Fatal(ctx, "http server start fail:", err)
2022-11-24 23:37:34 +08:00
}
2022-11-25 23:22:44 +08:00
})
2022-11-24 23:37:34 +08:00
// 信号监听
signalListen(ctx, signalHandlerForOverall)
select {
case <-serverCloseSignal:
// ...
}
g.Log().Info(ctx, "service successfully closed ..")
return
},
}
)
func init() {
if err := Main.AddCommand(Http, Queue, Tools, Auth, All, Help); err != nil {
2022-11-24 23:37:34 +08:00
panic(err)
}
serverCloseSignal = make(chan struct{}, 1)
}