From a9d84c2db9868ca24e8571fcb4aade0653bdb032 Mon Sep 17 00:00:00 2001 From: ayflying Date: Wed, 2 Apr 2025 11:43:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=96=B0=E7=9A=84=E8=B7=AF?= =?UTF-8?q?=E7=94=B1=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/load.go | 11 +++++++++++ internal/boot/boot.go | 30 ++++++++++++++++++++++++++++++ utility.go | 24 ++++++------------------ 3 files changed, 47 insertions(+), 18 deletions(-) create mode 100644 internal/boot/boot.go 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) + } }