feat 服务发现模块

This commit is contained in:
2026-01-18 00:08:55 +08:00
parent ba16c2cce3
commit 73d3361f34
4 changed files with 4 additions and 8 deletions

View File

@@ -2,7 +2,6 @@ package app
import (
"fmt"
"git.hlsq.asia/mmorpg/service-common/discover"
"git.hlsq.asia/mmorpg/service-common/discover/common"
"git.hlsq.asia/mmorpg/service-common/log"
"git.hlsq.asia/mmorpg/service-common/module"
@@ -27,6 +26,7 @@ func (p *Program) Init(_ svc.Environment) error {
p.moduleList = append(p.moduleList, &ModuleLoginQueue{})
p.moduleList = append(p.moduleList, (&module.Prometheus{}).Bind(config.Get().Metric))
p.moduleList = append(p.moduleList, (&module.Tracer{}).Bind(config.Get().Metric, common.KeyDiscoverServiceNameGateway))
p.moduleList = append(p.moduleList, &module.Discover{})
for i, m := range p.moduleList {
if i == 0 {
@@ -46,14 +46,12 @@ func (p *Program) Start() error {
return err
}
}
discover.Listen()
log.Infof(fmt.Sprintf("%v Start successful...", config.Get().App.Name))
return nil
}
func (p *Program) Stop() error {
discover.Close()
for i := len(p.moduleList) - 1; i >= 0; i-- {
m := p.moduleList[i]
if err := m.Stop(); err != nil {

2
go.mod
View File

@@ -4,7 +4,7 @@ go 1.24.0
require (
bou.ke/monkey v1.0.2
git.hlsq.asia/mmorpg/service-common v0.0.0-20260116155014-3de703eb83c5
git.hlsq.asia/mmorpg/service-common v0.0.0-20260117160658-22d48542a852
github.com/alicebob/miniredis/v2 v2.35.0
github.com/gin-contrib/cors v1.7.6
github.com/gin-gonic/gin v1.11.0

4
go.sum
View File

@@ -2,8 +2,8 @@ bou.ke/monkey v1.0.2 h1:kWcnsrCNUatbxncxR/ThdYqbytgOIArtYWqcQLQzKLI=
bou.ke/monkey v1.0.2/go.mod h1:OqickVX3tNx6t33n1xvtTtu85YN5s6cKwVug+oHMaIA=
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
git.hlsq.asia/mmorpg/service-common v0.0.0-20260116155014-3de703eb83c5 h1:b7pTgEyYUKpHtAAt4ea/3EYfX0Y0lYwhjrgf3kTyn0w=
git.hlsq.asia/mmorpg/service-common v0.0.0-20260116155014-3de703eb83c5/go.mod h1:Dazg+4woCv9Jk7jgT2qUSGWhZOXx/0WYfJO+FCUDyhw=
git.hlsq.asia/mmorpg/service-common v0.0.0-20260117160658-22d48542a852 h1:ehZ54MgGL3CO7KKDPxybFabIXxiQud1TGMcKjrSTcnw=
git.hlsq.asia/mmorpg/service-common v0.0.0-20260117160658-22d48542a852/go.mod h1:Dazg+4woCv9Jk7jgT2qUSGWhZOXx/0WYfJO+FCUDyhw=
github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0=
github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/alicebob/miniredis/v2 v2.35.0 h1:QwLphYqCEAo1eu1TqPRN2jgVMPBweeQcR21jeqDCONI=

View File

@@ -1,7 +1,6 @@
package global
import (
"git.hlsq.asia/mmorpg/service-common/log"
"github.com/prometheus/client_golang/prometheus"
)
@@ -11,7 +10,6 @@ var (
)
func init() {
log.Infof("Init prometheus metric...")
OnlineUsersGauge = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "gateway_online_users",
Help: "Total number of online users",