diff --git a/cmd/load.go b/cmd/load.go index 7ac74f9..f206883 100644 --- a/cmd/load.go +++ b/cmd/load.go @@ -3,8 +3,19 @@ package cmd import ( "github.com/ayflying/utility_go/controller/callback" "github.com/gogf/gf/v2/net/ghttp" + "github.com/prometheus/client_golang/prometheus/promhttp" ) +func Load(s *ghttp.Server) { + + //开启prometheus监控 + s.Group("/metrics", func(group *ghttp.RouterGroup) { + group.Bind( + ghttp.WrapH(promhttp.Handler()), + ) + }) +} + // 注册游客方法 func RegistrationAnonymous(group *ghttp.RouterGroup) (res []interface{}) { group.Bind( diff --git a/internal/boot/boot.go b/internal/boot/boot.go new file mode 100644 index 0000000..0ff1cdf --- /dev/null +++ b/internal/boot/boot.go @@ -0,0 +1,30 @@ +package boot + +import ( + "context" + v1 "github.com/ayflying/utility_go/api/system/v1" + "github.com/ayflying/utility_go/service" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/gctx" + "github.com/gogf/gf/v2/os/gtimer" + "github.com/prometheus/client_golang/prometheus" + "time" +) + +var ( + ctx = gctx.GetInitCtx() +) + +func Boot() (err error) { + err = service.SystemCron().StartCron() + + //用户活动持久化 + gtimer.SetTimeout(ctx, time.Minute, func(ctx context.Context) { + service.SystemCron().AddCron(v1.CronType_DAILY, func() error { + service.GameAct().Saves() + return nil + }) + }) + + return nil +} diff --git a/utility.go b/utility.go index 00fb9a7..b27a0e0 100644 --- a/utility.go +++ b/utility.go @@ -1,17 +1,11 @@ package utility_go import ( + "github.com/ayflying/utility_go/internal/boot" _ "github.com/ayflying/utility_go/internal/logic" - "context" - "time" - - v1 "github.com/ayflying/utility_go/api/system/v1" - "github.com/ayflying/utility_go/service" - "github.com/gogf/gf/v2/os/gctx" - "github.com/gogf/gf/v2/os/gtimer" - "github.com/ayflying/utility_go/config" + "github.com/gogf/gf/v2/os/gctx" ) var ( @@ -20,14 +14,8 @@ var ( ) func init() { - service.SystemCron().StartCron() - - //用户活动持久化 - gtimer.SetTimeout(ctx, time.Minute, func(ctx context.Context) { - service.SystemCron().AddCron(v1.CronType_DAILY, func() error { - service.GameAct().Saves() - return nil - }) - }) - + var err = boot.Boot() + if err != nil { + panic(err) + } }