hotgo/server/internal/cmd/cmd.go
2023-05-31 16:36:21 +08:00

83 lines
2.3 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
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @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"
"hotgo/utility/simple"
)
var (
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: "查看帮助",
Description: `
命令提示符
---------------------------------------------------------------------------------
启动服务
>> 所有服务 [go run main.go] 热编译 [gf run main.go]
>> HTTP服务 [go run main.go http]
>> 消息队列 [go run main.go queue]
>> 定时任务 [go run main.go cron]
>> 查看帮助 [go run main.go help]
---------------------------------------------------------------------------------
工具
>> 释放casbin权限用于清理无效的权限设置 [go run main.go tools -m=casbin -a1=refresh]
---------------------------------------------------------------------------------
更多
github地址https://github.com/bufanyun/hotgo
文档地址https://github.com/bufanyun/hotgo/tree/v2.0/docs/guide-zh-CN
HotGo框架交流1群190966648
`,
}
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")
// 需要启动的服务
var allServers = []*gcmd.Command{Http, Queue, Cron}
for _, server := range allServers {
var cmd = server
simple.SafeGo(ctx, func(ctx context.Context) {
if err := cmd.Func(ctx, parser); err != nil {
g.Log().Fatalf(ctx, "%v start fail:%v", cmd.Name, err)
}
})
}
// 信号监听
signalListen(ctx, signalHandlerForOverall)
<-serverCloseSignal
serverWg.Wait()
g.Log().Debug(ctx, "all service successfully closed ..")
return
},
}
)
func init() {
if err := Main.AddCommand(All, Http, Queue, Cron, Auth, Tools, Help); err != nil {
panic(err)
}
}