2022-11-24 23:37:34 +08:00
|
|
|
|
// Package cmd
|
|
|
|
|
// @Link https://github.com/bufanyun/hotgo
|
|
|
|
|
// @Copyright Copyright (c) 2022 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"
|
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{
|
2023-01-18 16:23:39 +08:00
|
|
|
|
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-12-15 16:12:08 +08:00
|
|
|
|
命令提示符
|
2022-11-24 23:37:34 +08:00
|
|
|
|
---------------------------------------------------------------------------------
|
|
|
|
|
启动服务
|
2023-01-18 16:23:39 +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]
|
2023-01-18 16:23:39 +08:00
|
|
|
|
>> 查看帮助 [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
|
|
|
|
|
2023-01-18 16:23:39 +08:00
|
|
|
|
---------------------------------------------------------------------------------
|
|
|
|
|
更多
|
|
|
|
|
github地址:https://github.com/bufanyun/hotgo
|
|
|
|
|
文档地址:文档正在书写中,请耐心等一等。
|
|
|
|
|
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) {
|
2023-01-18 16:23:39 +08:00
|
|
|
|
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) {
|
2022-11-24 23:37:34 +08:00
|
|
|
|
if err := Http.Func(ctx, parser); err != nil {
|
|
|
|
|
g.Log().Fatal(ctx, "http server start fail:", err)
|
|
|
|
|
}
|
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) {
|
2022-11-24 23:37:34 +08:00
|
|
|
|
if err := Queue.Func(ctx, parser); err != nil {
|
|
|
|
|
g.Log().Fatal(ctx, "queue consumer start fail:", err)
|
|
|
|
|
}
|
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, All, Help); err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
serverCloseSignal = make(chan struct{}, 1)
|
|
|
|
|
}
|