feat app 模块

This commit is contained in:
2026-01-16 22:07:09 +08:00
parent 05f6e0a716
commit 93c0d20eba
6 changed files with 243 additions and 102 deletions

View File

@@ -4,6 +4,7 @@ import (
"context"
"errors"
"git.hlsq.asia/mmorpg/service-common/log"
"git.hlsq.asia/mmorpg/service-common/module"
"net/http"
_ "net/http/pprof"
"sync"
@@ -15,12 +16,12 @@ type ModulePprof struct {
server *http.Server
}
func (m *ModulePprof) init() error {
func (m *ModulePprof) Init() error {
m.wg = &sync.WaitGroup{}
return nil
}
func (m *ModulePprof) start() error {
func (m *ModulePprof) Start() error {
m.wg.Add(1)
go func() {
defer m.wg.Done()
@@ -35,10 +36,14 @@ func (m *ModulePprof) start() error {
return nil
}
func (m *ModulePprof) stop() error {
func (m *ModulePprof) Stop() error {
if err := m.server.Shutdown(context.Background()); err != nil {
log.Errorf("stop pprof server failed: %v", err)
}
m.wg.Wait()
return nil
}
func (m *ModulePprof) Bind(_ ...any) module.Module {
return m
}