feat app 模块

This commit is contained in:
2026-01-16 22:07:06 +08:00
parent f5cbede966
commit 692f65b80f
10 changed files with 187 additions and 143 deletions

View File

@@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"git.hlsq.asia/mmorpg/service-common/log"
"git.hlsq.asia/mmorpg/service-common/module"
"git.hlsq.asia/mmorpg/service-gateway/config"
"git.hlsq.asia/mmorpg/service-gateway/internal/global"
"github.com/prometheus/client_golang/prometheus"
@@ -19,7 +20,7 @@ type ModulePrometheus struct {
server *http.Server
}
func (m *ModulePrometheus) init() error {
func (m *ModulePrometheus) Init() error {
m.wg = &sync.WaitGroup{}
global.OnlineUsersGauge = prometheus.NewGauge(prometheus.GaugeOpts{
@@ -31,7 +32,7 @@ func (m *ModulePrometheus) init() error {
return nil
}
func (m *ModulePrometheus) start() error {
func (m *ModulePrometheus) Start() error {
m.wg.Add(1)
go func() {
defer m.wg.Done()
@@ -47,10 +48,14 @@ func (m *ModulePrometheus) start() error {
return nil
}
func (m *ModulePrometheus) stop() error {
func (m *ModulePrometheus) Stop() error {
if err := m.server.Shutdown(context.Background()); err != nil {
log.Errorf("stop prometheus server failed: %v", err)
}
m.wg.Wait()
return nil
}
func (m *ModulePrometheus) Bind(_ ...any) module.Module {
return m
}