Compare commits

15 Commits

29 changed files with 410 additions and 265 deletions

View File

@@ -2,12 +2,14 @@ package app
import ( import (
"fmt" "fmt"
"git.hlsq.asia/mmorpg/service-common/discover"
"git.hlsq.asia/mmorpg/service-common/discover/common" "git.hlsq.asia/mmorpg/service-common/discover/common"
"git.hlsq.asia/mmorpg/service-common/log" "git.hlsq.asia/mmorpg/service-common/log"
"git.hlsq.asia/mmorpg/service-common/module" "git.hlsq.asia/mmorpg/service-common/module"
"git.hlsq.asia/mmorpg/service-gateway/config" "git.hlsq.asia/mmorpg/service-gateway/config"
"git.hlsq.asia/mmorpg/service-gateway/internal/global"
"git.hlsq.asia/mmorpg/service-gateway/internal/grpc_server"
"github.com/judwhite/go-svc" "github.com/judwhite/go-svc"
"sync"
) )
type Program struct { type Program struct {
@@ -15,23 +17,18 @@ type Program struct {
} }
func (p *Program) Init(_ svc.Environment) error { func (p *Program) Init(_ svc.Environment) error {
base := &ModuleBase{} p.moduleList = append(p.moduleList, &module.Log{Cfg: config.Get().Log})
if err := base.Init(); err != nil { p.moduleList = append(p.moduleList, &module.DB{Cfg: config.Get().DB, AppName: config.Get().App.Name})
return err p.moduleList = append(p.moduleList, &module.Snowflake{})
}
p.moduleList = append(p.moduleList, base)
p.moduleList = append(p.moduleList, (&module.DB{}).Bind(config.Get().DB))
p.moduleList = append(p.moduleList, &ModuleWebServer{}) p.moduleList = append(p.moduleList, &ModuleWebServer{})
p.moduleList = append(p.moduleList, &ModuleWebsocketServer{}) p.moduleList = append(p.moduleList, &ModuleWebsocketServer{})
p.moduleList = append(p.moduleList, &ModuleGrpcServer{})
p.moduleList = append(p.moduleList, &ModuleLoginQueue{}) p.moduleList = append(p.moduleList, &ModuleLoginQueue{})
p.moduleList = append(p.moduleList, (&module.Prometheus{}).Bind(config.Get().Metric)) p.moduleList = append(p.moduleList, &module.Grpc{Server: grpc_server.NewServer(config.Get().Serve.Grpc)})
p.moduleList = append(p.moduleList, (&module.Tracer{}).Bind(config.Get().Metric, common.KeyDiscoverServiceNameGateway)) p.moduleList = append(p.moduleList, &module.Prometheus{Cfg: config.Get().Metric})
p.moduleList = append(p.moduleList, &module.Tracer{Cfg: config.Get().Metric, ServiceName: common.KeyDiscoverServiceNameGateway})
p.moduleList = append(p.moduleList, &module.Discover{})
for i, m := range p.moduleList { for _, m := range p.moduleList {
if i == 0 {
continue
}
if err := m.Init(); err != nil { if err := m.Init(); err != nil {
return err return err
} }
@@ -41,19 +38,26 @@ func (p *Program) Init(_ svc.Environment) error {
} }
func (p *Program) Start() error { func (p *Program) Start() error {
ready := &sync.WaitGroup{}
ready.Add(len(p.moduleList))
for _, m := range p.moduleList { for _, m := range p.moduleList {
if err := m.Start(); err != nil { if err := m.Start(ready); err != nil {
return err return err
} }
} }
discover.Listen() ready.Wait()
for _, m := range p.moduleList {
if err := m.AfterStart(); err != nil {
return err
}
}
global.ServiceStatus = global.ServiceStatusReady
log.Infof(fmt.Sprintf("%v Start successful...", config.Get().App.Name)) log.Infof(fmt.Sprintf("%v Start successful...", config.Get().App.Name))
return nil return nil
} }
func (p *Program) Stop() error { func (p *Program) Stop() error {
discover.Close()
for i := len(p.moduleList) - 1; i >= 0; i-- { for i := len(p.moduleList) - 1; i >= 0; i-- {
m := p.moduleList[i] m := p.moduleList[i]
if err := m.Stop(); err != nil { if err := m.Stop(); err != nil {

View File

@@ -1,38 +0,0 @@
package app
import (
"git.hlsq.asia/mmorpg/service-common/log"
"git.hlsq.asia/mmorpg/service-common/module"
"git.hlsq.asia/mmorpg/service-common/utils"
"git.hlsq.asia/mmorpg/service-gateway/config"
"math/rand"
)
// ModuleBase 基础模块,或者一些零散的模块
type ModuleBase struct {
}
func (m *ModuleBase) Init() error {
// 配置
if err := config.LoadConfig(); err != nil {
return err
}
cfg := config.Get()
// 日志
log.Init(cfg.Log.Debug, cfg.Log.MaxSize, cfg.Log.MaxBackups, cfg.Log.MaxAge, cfg.Log.Level)
// 雪花
utils.InitSnowflake(int64(rand.Intn(1000)))
return nil
}
func (m *ModuleBase) Start() error {
return nil
}
func (m *ModuleBase) Stop() error {
return nil
}
func (m *ModuleBase) Bind(_ ...any) module.Module {
return m
}

View File

@@ -1,32 +0,0 @@
package app
import (
"git.hlsq.asia/mmorpg/service-common/module"
"git.hlsq.asia/mmorpg/service-common/net/grpc/service"
"git.hlsq.asia/mmorpg/service-gateway/config"
"git.hlsq.asia/mmorpg/service-gateway/internal/grpc_server"
)
// ModuleGrpcServer Grpc服务模块
type ModuleGrpcServer struct {
server service.IService
}
func (m *ModuleGrpcServer) Init() error {
return nil
}
func (m *ModuleGrpcServer) Start() error {
m.server = grpc_server.NewServer(config.Get().Serve.Grpc.TTL)
m.server.Init(config.Get().Serve.Grpc.Address, config.Get().Serve.Grpc.Port)
return nil
}
func (m *ModuleGrpcServer) Stop() error {
m.server.Close()
return nil
}
func (m *ModuleGrpcServer) Bind(_ ...any) module.Module {
return m
}

View File

@@ -5,10 +5,12 @@ import (
"git.hlsq.asia/mmorpg/service-gateway/internal/global" "git.hlsq.asia/mmorpg/service-gateway/internal/global"
"git.hlsq.asia/mmorpg/service-gateway/internal/handler/ws_handler/login" "git.hlsq.asia/mmorpg/service-gateway/internal/handler/ws_handler/login"
"runtime" "runtime"
"sync"
) )
// ModuleLoginQueue 登录队列模块 // ModuleLoginQueue 登录队列模块
type ModuleLoginQueue struct { type ModuleLoginQueue struct {
module.DefaultModule
login *login.Login login *login.Login
queueUp *login.QueueUp queueUp *login.QueueUp
} }
@@ -19,8 +21,9 @@ func (m *ModuleLoginQueue) Init() error {
return nil return nil
} }
func (m *ModuleLoginQueue) Start() error { func (m *ModuleLoginQueue) Start(ready *sync.WaitGroup) error {
m.login.Start(runtime.NumCPU()) m.login.Start(runtime.NumCPU())
ready.Done()
return nil return nil
} }
@@ -28,7 +31,3 @@ func (m *ModuleLoginQueue) Stop() error {
m.login.Stop() m.login.Stop()
return nil return nil
} }
func (m *ModuleLoginQueue) Bind(_ ...any) module.Module {
return m
}

View File

@@ -14,6 +14,7 @@ import (
// ModuleWebServer Web服务模块 // ModuleWebServer Web服务模块
type ModuleWebServer struct { type ModuleWebServer struct {
module.DefaultModule
wg *sync.WaitGroup wg *sync.WaitGroup
server *http.Server server *http.Server
} }
@@ -23,7 +24,7 @@ func (m *ModuleWebServer) Init() error {
return nil return nil
} }
func (m *ModuleWebServer) Start() error { func (m *ModuleWebServer) Start(ready *sync.WaitGroup) error {
m.wg.Add(1) m.wg.Add(1)
go func() { go func() {
defer m.wg.Done() defer m.wg.Done()
@@ -31,6 +32,7 @@ func (m *ModuleWebServer) Start() error {
Addr: fmt.Sprintf("%v:%v", config.Get().Serve.Http.Address, config.Get().Serve.Http.Port), Addr: fmt.Sprintf("%v:%v", config.Get().Serve.Http.Address, config.Get().Serve.Http.Port),
Handler: http_gateway.InitRouter(), Handler: http_gateway.InitRouter(),
} }
ready.Done()
if err := m.server.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) { if err := m.server.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
log.Errorf("http server failed: %v", err.Error()) log.Errorf("http server failed: %v", err.Error())
} }
@@ -46,7 +48,3 @@ func (m *ModuleWebServer) Stop() error {
m.wg.Wait() m.wg.Wait()
return nil return nil
} }
func (m *ModuleWebServer) Bind(_ ...any) module.Module {
return m
}

View File

@@ -14,6 +14,7 @@ import (
// ModuleWebsocketServer Websocket服务模块 // ModuleWebsocketServer Websocket服务模块
type ModuleWebsocketServer struct { type ModuleWebsocketServer struct {
module.DefaultModule
wg *sync.WaitGroup wg *sync.WaitGroup
server *websocket.WSServer server *websocket.WSServer
} }
@@ -28,10 +29,11 @@ func (m *ModuleWebsocketServer) Init() error {
return nil return nil
} }
func (m *ModuleWebsocketServer) Start() error { func (m *ModuleWebsocketServer) Start(ready *sync.WaitGroup) error {
m.wg.Add(1) m.wg.Add(1)
go func() { go func() {
defer m.wg.Done() defer m.wg.Done()
ready.Done()
_ = m.server.Run( _ = m.server.Run(
fmt.Sprintf("tcp4://0.0.0.0:%v", config.Get().Serve.Socket.Web.Port), fmt.Sprintf("tcp4://0.0.0.0:%v", config.Get().Serve.Socket.Web.Port),
true, true,
@@ -55,7 +57,3 @@ func (m *ModuleWebsocketServer) Stop() error {
m.wg.Wait() m.wg.Wait()
return nil return nil
} }
func (m *ModuleWebsocketServer) Bind(_ ...any) module.Module {
return m
}

View File

@@ -13,19 +13,19 @@ metric:
address: "0.0.0.0" address: "0.0.0.0"
port: 18504 port: 18504
jaeger: jaeger:
endpoint: "47.108.184.184:4317" endpoint: "127.0.0.1:4317"
db: db:
etcd: etcd:
endpoints: [ "10.0.40.9:2379" ] endpoints: [ "127.0.0.1:2379" ]
redis: redis:
addr: "47.108.184.184:6379" addr: "127.0.0.1:6379"
password: "lQ7aM8oB6lK0iD5k" password: "lQ7aM8oB6lK0iD5k"
db: 0 db: 0
serve: serve:
grpc: grpc:
address: "10.0.40.199" address: "127.0.0.1"
port: 18500 port: 18500
ttl: 20 ttl: 20
socket: socket:
@@ -40,6 +40,5 @@ serve:
port: 18503 port: 18503
auth: auth:
secret: "bMa3mU4oCsX2KBex5o7GzwSnACpumFq3SdlDXYZgVTU=" shortExpire: 3600
shortExpire: 60 longExpire: 604800
longExpire: 10080

View File

@@ -14,7 +14,6 @@ type Config struct {
} }
type AuthConfig struct { type AuthConfig struct {
Secret string `yaml:"secret"`
ShortExpire int64 `yaml:"shortExpire"` ShortExpire int64 `yaml:"shortExpire"`
LongExpire int64 `yaml:"longExpire"` LongExpire int64 `yaml:"longExpire"`
} }

View File

@@ -40,6 +40,5 @@ serve:
port: 18503 port: 18503
auth: auth:
secret: "bMa3mU4oCsX2KBex5o7GzwSnACpumFq3SdlDXYZgVTU=" shortExpire: 3600
shortExpire: 15 longExpire: 604800
longExpire: 10080

1
deploy/Jenkinsfile vendored
View File

@@ -80,6 +80,7 @@ pipeline {
sh """ sh """
echo "$DOCKER_PASS" | docker login --username "$DOCKER_USER" --password-stdin ${env.REGISTRY_URL} echo "$DOCKER_PASS" | docker login --username "$DOCKER_USER" --password-stdin ${env.REGISTRY_URL}
docker buildx build --platform linux/amd64 -t ${env.IMAGE_TAG} -f deploy/Dockerfile . --push docker buildx build --platform linux/amd64 -t ${env.IMAGE_TAG} -f deploy/Dockerfile . --push
docker rmi ${env.IMAGE_TAG}
docker logout ${env.REGISTRY_URL} docker logout ${env.REGISTRY_URL}
""" """
} }

21
go.mod
View File

@@ -4,16 +4,16 @@ go 1.24.0
require ( require (
bou.ke/monkey v1.0.2 bou.ke/monkey v1.0.2
git.hlsq.asia/mmorpg/service-common v0.0.0-20260116143417-d944729ad0e5 git.hlsq.asia/mmorpg/service-common v0.0.0-20260207051302-0ca8a0ccbb14
github.com/alicebob/miniredis/v2 v2.35.0 github.com/alicebob/miniredis/v2 v2.35.0
github.com/gin-contrib/cors v1.7.6 github.com/gin-contrib/cors v1.7.6
github.com/gin-gonic/gin v1.11.0 github.com/gin-gonic/gin v1.11.0
github.com/golang/mock v1.6.0 github.com/golang/mock v1.6.0
github.com/google/uuid v1.6.0
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.3 github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.3
github.com/judwhite/go-svc v1.2.1 github.com/judwhite/go-svc v1.2.1
github.com/panjf2000/gnet/v2 v2.9.7 github.com/panjf2000/gnet/v2 v2.9.7
github.com/prometheus/client_golang v1.20.5 github.com/prometheus/client_golang v1.20.5
github.com/redis/go-redis/v9 v9.10.0
github.com/stretchr/testify v1.11.1 github.com/stretchr/testify v1.11.1
go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin v0.64.0 go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin v0.64.0
go.uber.org/zap v1.27.0 go.uber.org/zap v1.27.0
@@ -23,6 +23,7 @@ require (
require ( require (
filippo.io/edwards25519 v1.1.0 // indirect filippo.io/edwards25519 v1.1.0 // indirect
github.com/IBM/sarama v1.46.3 // indirect
github.com/beorn7/perks v1.0.1 // indirect github.com/beorn7/perks v1.0.1 // indirect
github.com/bwmarrin/snowflake v0.3.0 // indirect github.com/bwmarrin/snowflake v0.3.0 // indirect
github.com/bytedance/gopkg v0.1.3 // indirect github.com/bytedance/gopkg v0.1.3 // indirect
@@ -35,6 +36,9 @@ require (
github.com/coreos/go-systemd/v22 v22.5.0 // indirect github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/eapache/go-resiliency v1.7.0 // indirect
github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3 // indirect
github.com/eapache/queue v1.1.0 // indirect
github.com/fsnotify/fsnotify v1.9.0 // indirect github.com/fsnotify/fsnotify v1.9.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.11 // indirect github.com/gabriel-vasile/mimetype v1.4.11 // indirect
github.com/gin-contrib/sse v1.1.0 // indirect github.com/gin-contrib/sse v1.1.0 // indirect
@@ -53,11 +57,17 @@ require (
github.com/gogo/protobuf v1.3.2 // indirect github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v5 v5.3.0 // indirect github.com/golang-jwt/jwt/v5 v5.3.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect github.com/golang/protobuf v1.5.4 // indirect
github.com/google/uuid v1.6.0 // indirect github.com/golang/snappy v0.0.4 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/jcmturner/aescts/v2 v2.0.0 // indirect
github.com/jcmturner/dnsutils/v2 v2.0.0 // indirect
github.com/jcmturner/gofork v1.7.6 // indirect
github.com/jcmturner/gokrb5/v8 v8.4.4 // indirect
github.com/jcmturner/rpc/v2 v2.0.3 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect github.com/jinzhu/now v1.1.5 // indirect
github.com/json-iterator/go v1.1.12 // indirect github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.9 // indirect github.com/klauspost/compress v1.18.1 // indirect
github.com/klauspost/cpuid/v2 v2.3.0 // indirect github.com/klauspost/cpuid/v2 v2.3.0 // indirect
github.com/leodido/go-urn v1.4.0 // indirect github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-isatty v0.0.20 // indirect
@@ -67,12 +77,15 @@ require (
github.com/natefinch/lumberjack v2.0.0+incompatible // indirect github.com/natefinch/lumberjack v2.0.0+incompatible // indirect
github.com/panjf2000/ants/v2 v2.11.3 // indirect github.com/panjf2000/ants/v2 v2.11.3 // indirect
github.com/pelletier/go-toml/v2 v2.2.4 // indirect github.com/pelletier/go-toml/v2 v2.2.4 // indirect
github.com/pierrec/lz4/v4 v4.1.22 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.6.1 // indirect github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.62.0 // indirect github.com/prometheus/common v0.62.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect github.com/prometheus/procfs v0.15.1 // indirect
github.com/quic-go/qpack v0.6.0 // indirect github.com/quic-go/qpack v0.6.0 // indirect
github.com/quic-go/quic-go v0.57.1 // indirect github.com/quic-go/quic-go v0.57.1 // indirect
github.com/rcrowley/go-metrics v0.0.0-20250401214520-65e299d6c5c9 // indirect
github.com/redis/go-redis/v9 v9.10.0 // indirect
github.com/sagikazarmark/locafero v0.11.0 // indirect github.com/sagikazarmark/locafero v0.11.0 // indirect
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 // indirect github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 // indirect
github.com/spf13/afero v1.15.0 // indirect github.com/spf13/afero v1.15.0 // indirect

63
go.sum
View File

@@ -2,10 +2,12 @@ bou.ke/monkey v1.0.2 h1:kWcnsrCNUatbxncxR/ThdYqbytgOIArtYWqcQLQzKLI=
bou.ke/monkey v1.0.2/go.mod h1:OqickVX3tNx6t33n1xvtTtu85YN5s6cKwVug+oHMaIA= 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 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
git.hlsq.asia/mmorpg/service-common v0.0.0-20260116143417-d944729ad0e5 h1:gkPNZ/OiXQhtiqRMdLrL5Zw580zgb9082jkZQqP71Fk= git.hlsq.asia/mmorpg/service-common v0.0.0-20260207051302-0ca8a0ccbb14 h1:4r3tNWRzGVY3Xx6UiGjJJnwoMoWlVqbyGrljxl5d/nQ=
git.hlsq.asia/mmorpg/service-common v0.0.0-20260116143417-d944729ad0e5/go.mod h1:Dazg+4woCv9Jk7jgT2qUSGWhZOXx/0WYfJO+FCUDyhw= git.hlsq.asia/mmorpg/service-common v0.0.0-20260207051302-0ca8a0ccbb14/go.mod h1:mMhZcumphj6gaVTppVYsMTkd+5HupmQgAc53Pd4MH9I=
github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0= github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0=
github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/IBM/sarama v1.46.3 h1:njRsX6jNlnR+ClJ8XmkO+CM4unbrNr/2vB5KK6UA+IE=
github.com/IBM/sarama v1.46.3/go.mod h1:GTUYiF9DMOZVe3FwyGT+dtSPceGFIgA+sPc5u6CBwko=
github.com/alicebob/miniredis/v2 v2.35.0 h1:QwLphYqCEAo1eu1TqPRN2jgVMPBweeQcR21jeqDCONI= github.com/alicebob/miniredis/v2 v2.35.0 h1:QwLphYqCEAo1eu1TqPRN2jgVMPBweeQcR21jeqDCONI=
github.com/alicebob/miniredis/v2 v2.35.0/go.mod h1:TcL7YfarKPGDAthEtl5NBeHZfeUQj6OXMm/+iu5cLMM= github.com/alicebob/miniredis/v2 v2.35.0/go.mod h1:TcL7YfarKPGDAthEtl5NBeHZfeUQj6OXMm/+iu5cLMM=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
@@ -37,6 +39,14 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/eapache/go-resiliency v1.7.0 h1:n3NRTnBn5N0Cbi/IeOHuQn9s2UwVUH7Ga0ZWcP+9JTA=
github.com/eapache/go-resiliency v1.7.0/go.mod h1:5yPzW0MIvSe0JDsv0v+DvcjEv2FyD6iZYSs1ZI+iQho=
github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3 h1:Oy0F4ALJ04o5Qqpdz8XLIpNA3WM/iSIXqxtqo7UGVws=
github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3/go.mod h1:YvSRo5mw33fLEx1+DlK6L2VV43tJt5Eyel9n9XBcR+0=
github.com/eapache/queue v1.1.0 h1:YOEu7KNc61ntiQlcEeUIoDTJ2o8mQznoNvUhiigpIqc=
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k= github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
@@ -85,13 +95,32 @@ github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.3 h1:NmZ1PKzSTQbuGHw9DGPFomqkkLWMC+vZCkfs+FHv1Vg= github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.3 h1:NmZ1PKzSTQbuGHw9DGPFomqkkLWMC+vZCkfs+FHv1Vg=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.3/go.mod h1:zQrxl1YP88HQlA6i9c63DSVPFklWpGX4OWAc9bFuaH4= github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.3/go.mod h1:zQrxl1YP88HQlA6i9c63DSVPFklWpGX4OWAc9bFuaH4=
github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8=
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/jcmturner/aescts/v2 v2.0.0 h1:9YKLH6ey7H4eDBXW8khjYslgyqG2xZikXP0EQFKrle8=
github.com/jcmturner/aescts/v2 v2.0.0/go.mod h1:AiaICIRyfYg35RUkr8yESTqvSy7csK90qZ5xfvvsoNs=
github.com/jcmturner/dnsutils/v2 v2.0.0 h1:lltnkeZGL0wILNvrNiVCR6Ro5PGU/SeBvVO/8c/iPbo=
github.com/jcmturner/dnsutils/v2 v2.0.0/go.mod h1:b0TnjGOvI/n42bZa+hmXL+kFJZsFT7G4t3HTlQ184QM=
github.com/jcmturner/gofork v1.7.6 h1:QH0l3hzAU1tfT3rZCnW5zXl+orbkNMMRGJfdJjHVETg=
github.com/jcmturner/gofork v1.7.6/go.mod h1:1622LH6i/EZqLloHfE7IeZ0uEJwMSUyQ/nDd82IeqRo=
github.com/jcmturner/goidentity/v6 v6.0.1 h1:VKnZd2oEIMorCTsFBnJWbExfNN7yZr3EhJAxwOkZg6o=
github.com/jcmturner/goidentity/v6 v6.0.1/go.mod h1:X1YW3bgtvwAXju7V3LCIMpY0Gbxyjn/mY9zx4tFonSg=
github.com/jcmturner/gokrb5/v8 v8.4.4 h1:x1Sv4HaTpepFkXbt2IkL29DXRf8sOfZXo8eRKh687T8=
github.com/jcmturner/gokrb5/v8 v8.4.4/go.mod h1:1btQEpgT6k+unzCwX1KdWMEwPPkkgBtP+F6aCACiMrs=
github.com/jcmturner/rpc/v2 v2.0.3 h1:7FXXj8Ti1IaVFpSAziCZWNzbNuZmnvw/i6CqLNdWfZY=
github.com/jcmturner/rpc/v2 v2.0.3/go.mod h1:VUJYCIDm3PVOEHw8sgt091/20OJjskO/YJki3ELg/Hc=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
@@ -102,8 +131,8 @@ github.com/judwhite/go-svc v1.2.1 h1:a7fsJzYUa33sfDJRF2N/WXhA+LonCEEY8BJb1tuS5tA
github.com/judwhite/go-svc v1.2.1/go.mod h1:mo/P2JNX8C07ywpP9YtO2gnBgnUiFTHqtsZekJrUuTk= github.com/judwhite/go-svc v1.2.1/go.mod h1:mo/P2JNX8C07ywpP9YtO2gnBgnUiFTHqtsZekJrUuTk=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA= github.com/klauspost/compress v1.18.1 h1:bcSGx7UbpBqMChDtsF28Lw6v/G94LPrrbMbdC3JH2co=
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= github.com/klauspost/compress v1.18.1/go.mod h1:ZQFFVG+MdnR0P+l6wpXgIL4NTtwiKIdBnrBd8Nrxr+0=
github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y= github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y=
github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0= github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
@@ -131,6 +160,8 @@ github.com/panjf2000/gnet/v2 v2.9.7 h1:6zW7Jl3oAfXwSuh1PxHLndoL2MQRWx0AJR6aaQjxU
github.com/panjf2000/gnet/v2 v2.9.7/go.mod h1:WQTxDWYuQ/hz3eccH0FN32IVuvZ19HewEWx0l62fx7E= github.com/panjf2000/gnet/v2 v2.9.7/go.mod h1:WQTxDWYuQ/hz3eccH0FN32IVuvZ19HewEWx0l62fx7E=
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4= github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY= github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
github.com/pierrec/lz4/v4 v4.1.22 h1:cKFw6uJDK+/gfw5BcDL0JL5aBsAFdsIT18eRtLj7VIU=
github.com/pierrec/lz4/v4 v4.1.22/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+bR9r+8l63Y= github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+bR9r+8l63Y=
@@ -145,6 +176,8 @@ github.com/quic-go/qpack v0.6.0 h1:g7W+BMYynC1LbYLSqRt8PBg5Tgwxn214ZZR34VIOjz8=
github.com/quic-go/qpack v0.6.0/go.mod h1:lUpLKChi8njB4ty2bFLX2x4gzDqXwUpaO1DP9qMDZII= github.com/quic-go/qpack v0.6.0/go.mod h1:lUpLKChi8njB4ty2bFLX2x4gzDqXwUpaO1DP9qMDZII=
github.com/quic-go/quic-go v0.57.1 h1:25KAAR9QR8KZrCZRThWMKVAwGoiHIrNbT72ULHTuI10= github.com/quic-go/quic-go v0.57.1 h1:25KAAR9QR8KZrCZRThWMKVAwGoiHIrNbT72ULHTuI10=
github.com/quic-go/quic-go v0.57.1/go.mod h1:ly4QBAjHA2VhdnxhojRsCUOeJwKYg+taDlos92xb1+s= github.com/quic-go/quic-go v0.57.1/go.mod h1:ly4QBAjHA2VhdnxhojRsCUOeJwKYg+taDlos92xb1+s=
github.com/rcrowley/go-metrics v0.0.0-20250401214520-65e299d6c5c9 h1:bsUq1dX0N8AOIL7EB/X911+m4EHsnWEHeJ0c+3TTBrg=
github.com/rcrowley/go-metrics v0.0.0-20250401214520-65e299d6c5c9/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/redis/go-redis/v9 v9.10.0 h1:FxwK3eV8p/CQa0Ch276C7u2d0eNC9kCmAYQ7mCXCzVs= github.com/redis/go-redis/v9 v9.10.0 h1:FxwK3eV8p/CQa0Ch276C7u2d0eNC9kCmAYQ7mCXCzVs=
github.com/redis/go-redis/v9 v9.10.0/go.mod h1:huWgSWd8mW6+m0VPhJjSSQ+d6Nh1VICQ6Q5lHuCH/Iw= github.com/redis/go-redis/v9 v9.10.0/go.mod h1:huWgSWd8mW6+m0VPhJjSSQ+d6Nh1VICQ6Q5lHuCH/Iw=
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ= github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
@@ -166,8 +199,10 @@ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSS
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
@@ -183,6 +218,7 @@ github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyC
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
github.com/yuin/gopher-lua v1.1.1 h1:kYKnWBjvbNP4XLT3+bPEwAXJx262OhaHDWDVOPjL46M= github.com/yuin/gopher-lua v1.1.1 h1:kYKnWBjvbNP4XLT3+bPEwAXJx262OhaHDWDVOPjL46M=
github.com/yuin/gopher-lua v1.1.1/go.mod h1:GBR0iDaNXjAgGg9zfCvksxSRnQx76gclCIb7kdAd1Pw= github.com/yuin/gopher-lua v1.1.1/go.mod h1:GBR0iDaNXjAgGg9zfCvksxSRnQx76gclCIb7kdAd1Pw=
go.etcd.io/etcd/api/v3 v3.6.1 h1:yJ9WlDih9HT457QPuHt/TH/XtsdN2tubyxyQHSHPsEo= go.etcd.io/etcd/api/v3 v3.6.1 h1:yJ9WlDih9HT457QPuHt/TH/XtsdN2tubyxyQHSHPsEo=
@@ -232,22 +268,31 @@ golang.org/x/arch v0.23.0/go.mod h1:dNHoOeKiyja7GTvF9NJS1l3Z2yntpQNzgrjh1cU103A=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
golang.org/x/crypto v0.45.0 h1:jMBrvKuj23MTlT0bQEOBcAE0mjg8mK9RXFhRH6nyF3Q= golang.org/x/crypto v0.45.0 h1:jMBrvKuj23MTlT0bQEOBcAE0mjg8mK9RXFhRH6nyF3Q=
golang.org/x/crypto v0.45.0/go.mod h1:XTGrrkGJve7CYK7J8PEww4aY7gM3qMCElcJQ8n8JdX4= golang.org/x/crypto v0.45.0/go.mod h1:XTGrrkGJve7CYK7J8PEww4aY7gM3qMCElcJQ8n8JdX4=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY= golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY=
golang.org/x/net v0.47.0/go.mod h1:/jNxtkgq5yWUGYkaZGqo27cfGZ1c5Nen03aYrrKpVRU= golang.org/x/net v0.47.0/go.mod h1:/jNxtkgq5yWUGYkaZGqo27cfGZ1c5Nen03aYrrKpVRU=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.18.0 h1:kr88TuHDroi+UVf+0hZnirlk8o8T+4MrK6mr60WkH/I= golang.org/x/sync v0.18.0 h1:kr88TuHDroi+UVf+0hZnirlk8o8T+4MrK6mr60WkH/I=
golang.org/x/sync v0.18.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= golang.org/x/sync v0.18.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@@ -257,12 +302,20 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.39.0 h1:CvCKL8MeisomCi6qNZ+wbb0DN9E5AATixKsvNtMoMFk= golang.org/x/sys v0.39.0 h1:CvCKL8MeisomCi6qNZ+wbb0DN9E5AATixKsvNtMoMFk=
golang.org/x/sys v0.39.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= golang.org/x/sys v0.39.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.31.0 h1:aC8ghyu4JhP8VojJ2lEHBnochRno1sgL6nEi9WGFGMM= golang.org/x/text v0.31.0 h1:aC8ghyu4JhP8VojJ2lEHBnochRno1sgL6nEi9WGFGMM=
golang.org/x/text v0.31.0/go.mod h1:tKRAlv61yKIjGGHX/4tP1LTbc13YSec1pxVEWXzfoeM= golang.org/x/text v0.31.0/go.mod h1:tKRAlv61yKIjGGHX/4tP1LTbc13YSec1pxVEWXzfoeM=
golang.org/x/time v0.12.0 h1:ScB/8o8olJvc+CQPWrK3fPZNfh7qgwCrY0zJmoEQLSE= golang.org/x/time v0.12.0 h1:ScB/8o8olJvc+CQPWrK3fPZNfh7qgwCrY0zJmoEQLSE=
@@ -272,6 +325,7 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
@@ -291,6 +345,7 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntN
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc= gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc= gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@@ -1,8 +1,21 @@
package global package global
var ServiceStatus = ServiceStatusStarting
type ServiceStatusCode int32
const ( const (
KeyGatewayAccessToken = "gateway:token:access:%v" ServiceStatusStarting ServiceStatusCode = iota // 启动中
KeyGatewayRefreshToken = "gateway:token:refresh:%v" ServiceStatusReady // 就绪
ServiceStatusStopping // 停止中
)
var GatewaySID int64
const (
KeyGatewayAccessToken = "gateway:token:access:"
KeyGatewayRefreshToken = "gateway:token:refresh:"
KeyGatewaySession = "gateway:session:"
KeyGatewayInfo = "gateway:info:%v" KeyGatewayInfo = "gateway:info:%v"
HFieldInfoGatewaySID = "gateway_sid" HFieldInfoGatewaySID = "gateway_sid"

View File

@@ -1,19 +1,24 @@
package global package global
import ( import (
"git.hlsq.asia/mmorpg/service-common/log"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
) )
var ( var (
OnlineUsersGauge prometheus.Gauge OnlineUsersGauge prometheus.Gauge
FlowCounter prometheus.Counter
) )
func init() { func init() {
log.Infof("Init prometheus metric...")
OnlineUsersGauge = prometheus.NewGauge(prometheus.GaugeOpts{ OnlineUsersGauge = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "online_users", Name: "gateway_online_users",
Help: "Total number of online users", Help: "Total number of online users",
}) })
prometheus.MustRegister(OnlineUsersGauge) prometheus.MustRegister(OnlineUsersGauge)
FlowCounter = prometheus.NewCounter(prometheus.CounterOpts{
Name: "gateway_flow_counter",
Help: "Total number of flow",
})
prometheus.MustRegister(FlowCounter)
} }

View File

@@ -5,6 +5,7 @@ import (
"git.hlsq.asia/mmorpg/service-common/log" "git.hlsq.asia/mmorpg/service-common/log"
"git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb" "git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb"
"git.hlsq.asia/mmorpg/service-common/proto/ss/ss_pb" "git.hlsq.asia/mmorpg/service-common/proto/ss/ss_pb"
"git.hlsq.asia/mmorpg/service-gateway/internal/global"
"git.hlsq.asia/mmorpg/service-gateway/internal/handler/ws_handler/client" "git.hlsq.asia/mmorpg/service-gateway/internal/handler/ws_handler/client"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
"sync" "sync"
@@ -24,7 +25,7 @@ func (s *Server) ToClient(server grpc_pb.Gateway_ToClientServer) error {
if args, err := server.Recv(); err != nil { if args, err := server.Recv(); err != nil {
return return
} else { } else {
if args.USN == "" { if args.USN == -1 {
//utils.WorkerPool(ws_handler.UserMgr.GetAllInterface(), func(task interface{}) { //utils.WorkerPool(ws_handler.UserMgr.GetAllInterface(), func(task interface{}) {
// client := task.(*ws_handler.Client) // client := task.(*ws_handler.Client)
@@ -39,8 +40,10 @@ func (s *Server) ToClient(server grpc_pb.Gateway_ToClientServer) error {
log.Errorf("ToClient proto.Marshal error: %v", err) log.Errorf("ToClient proto.Marshal error: %v", err)
continue continue
} }
dataLen := float64(len(data))
for _, cli := range client.UserMgr.GetAll() { for _, cli := range client.UserMgr.GetAll() {
cli.WriteBytesPreMarshal(data) cli.WriteBytesPreMarshal(data)
global.FlowCounter.Add(dataLen)
} }
//for _, client := range ws_handler.UserMgr.GetAll() { //for _, client := range ws_handler.UserMgr.GetAll() {
@@ -49,6 +52,7 @@ func (s *Server) ToClient(server grpc_pb.Gateway_ToClientServer) error {
} else { } else {
if cli := client.UserMgr.GetByUSN(args.USN); cli != nil { if cli := client.UserMgr.GetByUSN(args.USN); cli != nil {
cli.WriteBytes(ss_pb.MessageID(args.MessageID), args.Payload) cli.WriteBytes(ss_pb.MessageID(args.MessageID), args.Payload)
global.FlowCounter.Add(float64(len(args.Payload)))
} }
} }
} }

View File

@@ -1,10 +1,11 @@
package grpc_server package grpc_server
import ( import (
"git.hlsq.asia/mmorpg/service-common/config"
"git.hlsq.asia/mmorpg/service-common/discover/common" "git.hlsq.asia/mmorpg/service-common/discover/common"
"git.hlsq.asia/mmorpg/service-common/net/grpc/service" "git.hlsq.asia/mmorpg/service-common/net/grpc/service"
"git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb" "git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb"
"git.hlsq.asia/mmorpg/service-gateway/internal/handler/ws_handler/client" "git.hlsq.asia/mmorpg/service-gateway/internal/global"
"google.golang.org/grpc" "google.golang.org/grpc"
) )
@@ -13,21 +14,26 @@ type Server struct {
service.Base service.Base
} }
func NewServer(ttl int64) *Server { func NewServer(cfg *config.GrpcConfig) *Server {
s := &Server{ s := &Server{
Base: service.Base{ Base: service.Base{
Target: common.KeyDiscoverGateway, Target: common.KeyDiscoverGateway,
ServiceName: common.KeyDiscoverServiceNameGateway, ServiceName: common.KeyDiscoverServiceNameGateway,
EtcdTTL: ttl, Cfg: cfg,
}, },
} }
s.Base.OnCustomGrpcServerOption = s.OnCustomGrpcServerOption
s.Base.OnInit = s.OnInit s.Base.OnInit = s.OnInit
s.Base.OnClose = s.OnClose s.Base.OnClose = s.OnClose
return s return s
} }
func (s *Server) OnCustomGrpcServerOption() []grpc.ServerOption {
return nil
}
func (s *Server) OnInit(serve *grpc.Server) { func (s *Server) OnInit(serve *grpc.Server) {
client.GatewaySID = s.SID global.GatewaySID = s.SID
grpc_pb.RegisterGatewayServer(serve, s) grpc_pb.RegisterGatewayServer(serve, s)
} }

View File

@@ -1,18 +1,14 @@
package http_handler package http_handler
import ( import (
"context"
"fmt"
"git.hlsq.asia/mmorpg/service-common/db/redis" "git.hlsq.asia/mmorpg/service-common/db/redis"
"git.hlsq.asia/mmorpg/service-common/log" "git.hlsq.asia/mmorpg/service-common/log"
"git.hlsq.asia/mmorpg/service-common/net/grpc/grpc_client" "git.hlsq.asia/mmorpg/service-common/net/grpc/grpc_client"
"git.hlsq.asia/mmorpg/service-common/net/http/http_resp" "git.hlsq.asia/mmorpg/service-common/net/http/http_resp"
"git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb" "git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb"
"git.hlsq.asia/mmorpg/service-common/utils" "git.hlsq.asia/mmorpg/service-common/utils"
"git.hlsq.asia/mmorpg/service-gateway/config"
"git.hlsq.asia/mmorpg/service-gateway/internal/global" "git.hlsq.asia/mmorpg/service-gateway/internal/global"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"time"
) )
// 这个模块处理用户登录 // 这个模块处理用户登录
@@ -24,7 +20,7 @@ type LoginReq struct {
} }
type LoginResp struct { type LoginResp struct {
USN string `json:"usn"` USN int64 `json:"usn"`
Name string `json:"name"` Name string `json:"name"`
AccessToken string `json:"accessToken"` AccessToken string `json:"accessToken"`
RefreshToken string `json:"refreshToken"` RefreshToken string `json:"refreshToken"`
@@ -43,7 +39,7 @@ func Login(c *gin.Context) {
return return
} }
usn, name := "", "" usn, name := int64(0), ""
if req.Phone != "" { if req.Phone != "" {
// TODO 校验验证码 // TODO 校验验证码
login, err := client.PhoneLogin(c, &grpc_pb.PhoneLoginReq{ login, err := client.PhoneLogin(c, &grpc_pb.PhoneLoginReq{
@@ -71,7 +67,12 @@ func Login(c *gin.Context) {
return return
} }
at, rt, err := genToken(c, usn) at, rt, err := sessionLogin(c, usn)
if err != nil {
log.Errorf("Login sessionLogin error: %v, usn: %v", err, usn)
http_resp.JsonOK(c, http_resp.Error(http_resp.Failed))
return
}
http_resp.JsonOK(c, http_resp.Success(&LoginResp{ http_resp.JsonOK(c, http_resp.Success(&LoginResp{
USN: usn, USN: usn,
Name: name, Name: name,
@@ -81,7 +82,7 @@ func Login(c *gin.Context) {
} }
type RefreshTokenReq struct { type RefreshTokenReq struct {
RefreshToken string `json:"refreshToken" binding:"required,min=1"` RefreshToken string `json:"refreshToken"`
} }
type RefreshTokenResp struct { type RefreshTokenResp struct {
@@ -95,18 +96,27 @@ func RefreshToken(c *gin.Context) {
http_resp.JsonBadRequest(c) http_resp.JsonBadRequest(c)
return return
} }
claims, err := utils.ParseToken(req.RefreshToken, config.Get().Auth.Secret) if req.RefreshToken == "" {
cookie, err := c.Cookie("refresh_token")
if err != nil { if err != nil {
http_resp.JsonUnauthorized(c) http_resp.JsonUnauthorized(c)
return return
} }
if redis.GetClient().Get(c, fmt.Sprintf(global.KeyGatewayRefreshToken, claims.USN)).Val() != req.RefreshToken { req.RefreshToken = cookie
}
usn, _ := redis.GetClient().HGet(c, global.KeyGatewayRefreshToken+req.RefreshToken, (&utils.UserSession{}).GetUsnKey()).Int64()
if usn == 0 {
http_resp.JsonUnauthorized(c) http_resp.JsonUnauthorized(c)
return return
} }
at, rt, err := genToken(c, claims.USN)
if err := sessionLogout(c, req.RefreshToken); err != nil {
log.Errorf("RefreshToken sessionLogout error: %v, usn: %v", err, usn)
}
at, rt, err := sessionLogin(c, usn)
if err != nil { if err != nil {
log.Errorf("RefreshToken genToken error: %v, usn: %v", err, claims.USN) log.Errorf("RefreshToken sessionLogin error: %v, usn: %v", err, usn)
http_resp.JsonOK(c, http_resp.Error(http_resp.Failed)) http_resp.JsonOK(c, http_resp.Error(http_resp.Failed))
return return
} }
@@ -117,23 +127,29 @@ func RefreshToken(c *gin.Context) {
})) }))
} }
func genToken(ctx context.Context, usn string) (string, string, error) { type LogoutReq struct {
at, err := genTokenOne(ctx, global.KeyGatewayAccessToken, usn, time.Duration(config.Get().Auth.ShortExpire)*time.Minute) RefreshToken string `json:"refreshToken"`
if err != nil {
return "", "", err
}
rt, err := genTokenOne(ctx, global.KeyGatewayRefreshToken, usn, time.Duration(config.Get().Auth.LongExpire)*time.Minute)
if err != nil {
return "", "", err
}
return at, rt, nil
} }
func genTokenOne(ctx context.Context, key string, usn string, ttl time.Duration) (string, error) { type LogoutResp struct {
token, err := utils.GenToken(usn, config.Get().Auth.Secret, ttl) }
if err != nil {
return "", err func Logout(c *gin.Context) {
} req := &LogoutReq{}
redis.GetClient().Set(ctx, fmt.Sprintf(key, usn), token, ttl) if err := c.ShouldBindJSON(req); err != nil {
return token, err http_resp.JsonBadRequest(c)
return
}
if req.RefreshToken == "" {
cookie, err := c.Cookie("refresh_token")
if err != nil {
http_resp.JsonUnauthorized(c)
return
}
req.RefreshToken = cookie
}
if err := sessionLogout(c, req.RefreshToken); err != nil {
log.Errorf("Logout sessionLogout error: %v", err)
}
http_resp.JsonOK(c, http_resp.Success(&LogoutResp{}))
} }

View File

@@ -2,23 +2,18 @@ package http_handler
import ( import (
"bou.ke/monkey" "bou.ke/monkey"
"context"
"fmt" "fmt"
"git.hlsq.asia/mmorpg/service-common/db/redis"
"git.hlsq.asia/mmorpg/service-common/net/grpc/grpc_client" "git.hlsq.asia/mmorpg/service-common/net/grpc/grpc_client"
"git.hlsq.asia/mmorpg/service-common/net/http/http_resp" "git.hlsq.asia/mmorpg/service-common/net/http/http_resp"
"git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb" "git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb"
"git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb/mocks" "git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb/mocks"
"git.hlsq.asia/mmorpg/service-common/utils" "git.hlsq.asia/mmorpg/service-common/utils"
"git.hlsq.asia/mmorpg/service-gateway/internal/global"
"git.hlsq.asia/mmorpg/service-gateway/internal/testutil" "git.hlsq.asia/mmorpg/service-gateway/internal/testutil"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/golang/mock/gomock" "github.com/golang/mock/gomock"
redis2 "github.com/redis/go-redis/v9"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
"net/http" "net/http"
"strconv"
"testing" "testing"
) )
@@ -26,17 +21,6 @@ type LoginTestSuite struct {
testutil.TestSuite testutil.TestSuite
} }
func (ts *LoginTestSuite) TestGenToken() {
usn := utils.RandInt(1, 100000000)
at, rt, err := genToken(context.Background(), strconv.Itoa(usn))
ts.Assert().NoError(err)
redisAt := redis.GetClient().Get(context.Background(), fmt.Sprintf(global.KeyGatewayAccessToken, usn)).Val()
ts.Assert().Equal(at, redisAt)
redisRt := redis.GetClient().Get(context.Background(), fmt.Sprintf(global.KeyGatewayRefreshToken, usn)).Val()
ts.Assert().Equal(rt, redisRt)
}
func (ts *LoginTestSuite) TestLogin() { func (ts *LoginTestSuite) TestLogin() {
gin.SetMode(gin.TestMode) gin.SetMode(gin.TestMode)
@@ -90,7 +74,7 @@ func (ts *LoginTestSuite) TestLogin() {
client := mocks.NewMockUserClient(ctrl) client := mocks.NewMockUserClient(ctrl)
client.EXPECT(). client.EXPECT().
PhoneLogin(gomock.Any(), gomock.Any()). PhoneLogin(gomock.Any(), gomock.Any()).
Return(&grpc_pb.PhoneLoginResp{USN: "1", Name: "hh"}, nil) Return(&grpc_pb.PhoneLoginResp{USN: 1, Name: "hh"}, nil)
monkey.Patch(grpc_client.UserNewClientLB, func() (grpc_pb.UserClient, error) { monkey.Patch(grpc_client.UserNewClientLB, func() (grpc_pb.UserClient, error) {
return client, nil return client, nil
@@ -130,41 +114,41 @@ func (ts *LoginTestSuite) TestRefreshToken() {
utils.AssertResponse(&ts.Suite, w, http.StatusOK, http_resp.TokenInvalid) utils.AssertResponse(&ts.Suite, w, http.StatusOK, http_resp.TokenInvalid)
}) })
ts.Run("Redis Get Failed", func() { //ts.Run("Redis Get Failed", func() {
monkey.Patch(utils.ParseToken, func(tokenString string, secret string) (*utils.Claims, error) { // monkey.Patch(utils.ParseToken, func(tokenString string, secret string) (*utils.Claims, error) {
if tokenString == "abc" { // if tokenString == "abc" {
return &utils.Claims{USN: "1"}, nil // return &utils.Claims{USN: 1}, nil
} // }
return nil, assert.AnError // return nil, assert.AnError
}) // })
defer monkey.Unpatch(utils.ParseToken) // defer monkey.Unpatch(utils.ParseToken)
//
redis.GetClient().Set(context.Background(), fmt.Sprintf(global.KeyGatewayRefreshToken, 1), "ab", redis2.KeepTTL) // redis.GetClient().Set(context.Background(), global.KeyGatewayRefreshToken+1, "ab", redis2.KeepTTL)
//
w, c := utils.CreateTestContext("POST", "/", &RefreshTokenReq{ // w, c := utils.CreateTestContext("POST", "/", &RefreshTokenReq{
RefreshToken: "abc", // RefreshToken: "abc",
}) // })
RefreshToken(c) // RefreshToken(c)
utils.AssertResponse(&ts.Suite, w, http.StatusOK, http_resp.TokenInvalid) // utils.AssertResponse(&ts.Suite, w, http.StatusOK, http_resp.TokenInvalid)
}) //})
//
ts.Run("OK", func() { //ts.Run("OK", func() {
monkey.Patch(utils.ParseToken, func(tokenString string, secret string) (*utils.Claims, error) { // monkey.Patch(utils.ParseToken, func(tokenString string, secret string) (*utils.Claims, error) {
if tokenString == "abc" { // if tokenString == "abc" {
return &utils.Claims{USN: "1"}, nil // return &utils.Claims{USN: 1}, nil
} // }
return nil, assert.AnError // return nil, assert.AnError
}) // })
defer monkey.Unpatch(utils.ParseToken) // defer monkey.Unpatch(utils.ParseToken)
//
redis.GetClient().Set(context.Background(), fmt.Sprintf(global.KeyGatewayRefreshToken, 1), "abc", redis2.KeepTTL) // redis.GetClient().Set(context.Background(), fmt.Sprintf(global.KeyGatewayRefreshToken, 1), "abc", redis2.KeepTTL)
//
w, c := utils.CreateTestContext("POST", "/", &RefreshTokenReq{ // w, c := utils.CreateTestContext("POST", "/", &RefreshTokenReq{
RefreshToken: "abc", // RefreshToken: "abc",
}) // })
RefreshToken(c) // RefreshToken(c)
utils.AssertResponse(&ts.Suite, w, http.StatusOK, http_resp.OK) // utils.AssertResponse(&ts.Suite, w, http.StatusOK, http_resp.OK)
}) //})
} }
func TestLoginTestSuite(t *testing.T) { func TestLoginTestSuite(t *testing.T) {

View File

@@ -0,0 +1,108 @@
package http_handler
import (
"git.hlsq.asia/mmorpg/service-common/db/redis"
"git.hlsq.asia/mmorpg/service-common/utils"
"git.hlsq.asia/mmorpg/service-gateway/config"
"git.hlsq.asia/mmorpg/service-gateway/internal/global"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
)
var (
scriptLoginSha1 string
scriptLogin = `
local at_key = KEYS[1] .. ARGV[1]
local rt_key = KEYS[2] .. ARGV[2]
local session_key = KEYS[3] .. ARGV[3]
redis.call("HSET", at_key,
"usn", ARGV[3],
"ip", ARGV[6],
"ua", ARGV[7],
"rt", ARGV[2]
)
redis.call("EXPIRE", at_key, tonumber(ARGV[4]))
redis.call("HSET", rt_key,
"usn", ARGV[3],
"ip", ARGV[6],
"ua", ARGV[7],
"at", ARGV[1]
)
redis.call("EXPIRE", rt_key, tonumber(ARGV[5]))
local all_rts = redis.call("SMEMBERS", session_key)
-- 只允许最大10个会话多了的随机踢掉
if #all_rts >= 10 then
local rk = KEYS[2] .. all_rts[1]
local ak = KEYS[1] .. redis.call("HGET", rk, "at")
redis.call("DEL", rk)
redis.call("DEL", ak)
end
-- 清理已经失效的会话
for i, rt in ipairs(all_rts) do
if redis.call("EXISTS", KEYS[2] .. rt) == 0 then
redis.call("SREM", session_key, rt)
end
end
redis.call("SADD", session_key, ARGV[2])
redis.call("EXPIRE", session_key, tonumber(ARGV[5]) + 600)
return 1
`
)
func sessionLogin(c *gin.Context, usn int64) (string, string, error) {
if scriptLoginSha1 == "" {
scriptLoginSha1 = redis.GetClient().ScriptLoad(c, scriptLogin).Val()
}
at := uuid.New().String()
rt := uuid.New().String()
err := redis.GetClient().EvalSha(
c, scriptLoginSha1,
[]string{global.KeyGatewayAccessToken, global.KeyGatewayRefreshToken, global.KeyGatewaySession},
at,
rt,
usn,
config.Get().Auth.ShortExpire,
config.Get().Auth.LongExpire,
c.RemoteIP(),
c.GetHeader("User-Agent"),
).Err()
if err != nil {
return "", "", utils.ErrorsWrap(err)
}
c.SetCookie("refresh_token", rt, int(config.Get().Auth.LongExpire), "/", ".hlsq.asia", true, true)
return at, rt, nil
}
var (
scriptLogoutSha1 string
scriptLogout = `
local rt_key = KEYS[2] .. ARGV[1]
local usn = redis.call("HGET", rt_key, "usn")
local at = redis.call("HGET", rt_key, "at")
local at_key = KEYS[1] .. at
local session_key = KEYS[3] .. usn
redis.call("DEL", at_key)
redis.call("DEL", rt_key)
redis.call("SREM", session_key, ARGV[1])
return 1
`
)
func sessionLogout(c *gin.Context, rt string) error {
if scriptLogoutSha1 == "" {
scriptLogoutSha1 = redis.GetClient().ScriptLoad(c, scriptLogout).Val()
}
return redis.GetClient().EvalSha(
c, scriptLogoutSha1,
[]string{global.KeyGatewayAccessToken, global.KeyGatewayRefreshToken, global.KeyGatewaySession},
rt,
).Err()
}

View File

@@ -13,8 +13,6 @@ import (
"time" "time"
) )
var GatewaySID string
type Client struct { type Client struct {
sync.WaitGroup sync.WaitGroup
conn socket.ISocketConn // Socket conn socket.ISocketConn // Socket
@@ -25,17 +23,16 @@ type Client struct {
heartBeat time.Time // 最后一次心跳 heartBeat time.Time // 最后一次心跳
Status int32 // 状态0 登陆中 1 正常 2 离线 Status int32 // 状态0 登陆中 1 正常 2 离线
USN string // 用户ID USN int64 // 用户ID
SceneSID string // 场景服ID SceneSID int64 // 场景服ID
InstanceID int32 // 副本ID副本类型 InstanceID int32 // 副本ID副本类型
UniqueNo string // 副本唯一编号 UniqueNo int64 // 副本唯一编号
} }
func NewClient(usn string, conn socket.ISocketConn) *Client { func NewClient(conn socket.ISocketConn) *Client {
client := &Client{ client := &Client{
USN: usn,
conn: conn, conn: conn,
logger: log.GetLogger().Named(fmt.Sprintf("usn:%v", usn)), logger: log.GetLogger(),
heartBeat: time.Now(), heartBeat: time.Now(),
mailChan: make(chan Event, 1024), mailChan: make(chan Event, 1024),
} }
@@ -45,6 +42,11 @@ func NewClient(usn string, conn socket.ISocketConn) *Client {
return client return client
} }
func (c *Client) SetUSN(usn int64) {
c.USN = usn
c.logger = log.GetLogger().Named(fmt.Sprintf("usn:%v", usn))
}
func (c *Client) Loop() { func (c *Client) Loop() {
defer func() { defer func() {
if err := recover(); err != nil { if err := recover(); err != nil {

View File

@@ -45,7 +45,7 @@ func (c *Client) handle(event Event) {
if c.Status == 0 { if c.Status == 0 {
c.Status = 1 c.Status = 1
UserMgr.Add(c.USN, c) UserMgr.Add(c.USN, c)
redis.GetClient().HSet(c.ctx, fmt.Sprintf(global.KeyGatewayInfo, c.USN), global.HFieldInfoGatewaySID, GatewaySID) redis.GetClient().HSet(c.ctx, fmt.Sprintf(global.KeyGatewayInfo, c.USN), global.HFieldInfoGatewaySID, global.GatewaySID)
c.WriteMessage(ss_pb.MessageID_MESSAGE_ID_LOGIN_SUCCESS, &ss_pb.S2C_LoginSuccess{ c.WriteMessage(ss_pb.MessageID_MESSAGE_ID_LOGIN_SUCCESS, &ss_pb.S2C_LoginSuccess{
InstanceID: 1, InstanceID: 1,
}) })
@@ -61,7 +61,7 @@ func (c *Client) onEnter(msg *ss_pb.C2S_EnterInstance) {
} }
resp, err := client.Enter(c.ctx, &grpc_pb.EnterReq{ resp, err := client.Enter(c.ctx, &grpc_pb.EnterReq{
USN: c.USN, USN: c.USN,
GatewaySID: GatewaySID, GatewaySID: global.GatewaySID,
InstanceID: msg.InstanceID, InstanceID: msg.InstanceID,
}) })
if err != nil { if err != nil {
@@ -75,7 +75,7 @@ func (c *Client) onEnter(msg *ss_pb.C2S_EnterInstance) {
} }
func (c *Client) onLeave() { func (c *Client) onLeave() {
if c.SceneSID == "" { if c.SceneSID == 0 {
return return
} }
client, err := grpc_client.SceneNewClient(c.SceneSID) client, err := grpc_client.SceneNewClient(c.SceneSID)
@@ -94,7 +94,7 @@ func (c *Client) onLeave() {
} }
func (c *Client) onAction(msg *ss_pb.C2S_Action) { func (c *Client) onAction(msg *ss_pb.C2S_Action) {
if c.SceneSID == "" { if c.SceneSID == 0 {
return return
} }
if err := grpc_client.SendMessageToScene(c.SceneSID, grpc_client.FunAction, &grpc_pb.ActionReq{ if err := grpc_client.SendMessageToScene(c.SceneSID, grpc_client.FunAction, &grpc_pb.ActionReq{

View File

@@ -8,35 +8,35 @@ import (
var UserMgr *userManager var UserMgr *userManager
type userManager struct { type userManager struct {
userMap map[string]*Client userMap map[int64]*Client
sync.RWMutex sync.RWMutex
} }
func init() { func init() {
UserMgr = &userManager{ UserMgr = &userManager{
userMap: make(map[string]*Client), userMap: make(map[int64]*Client),
} }
} }
func (m *userManager) Add(usn string, client *Client) { func (m *userManager) Add(usn int64, client *Client) {
m.Lock() m.Lock()
defer m.Unlock() defer m.Unlock()
m.userMap[usn] = client m.userMap[usn] = client
global.OnlineUsersGauge.Inc() global.OnlineUsersGauge.Inc()
} }
func (m *userManager) Delete(usn string) { func (m *userManager) Delete(usn int64) {
m.Lock() m.Lock()
defer m.Unlock() defer m.Unlock()
delete(m.userMap, usn) delete(m.userMap, usn)
global.OnlineUsersGauge.Dec() global.OnlineUsersGauge.Dec()
} }
func (m *userManager) GetAll() map[string]*Client { func (m *userManager) GetAll() map[int64]*Client {
m.RLock() m.RLock()
defer m.RUnlock() defer m.RUnlock()
copyMap := make(map[string]*Client, len(m.userMap)) copyMap := make(map[int64]*Client, len(m.userMap))
for k, v := range m.userMap { for k, v := range m.userMap {
copyMap[k] = v copyMap[k] = v
} }
@@ -54,7 +54,7 @@ func (m *userManager) GetAllInterface() []interface{} {
return r return r
} }
func (m *userManager) GetByUSN(usn string) *Client { func (m *userManager) GetByUSN(usn int64) *Client {
m.RLock() m.RLock()
defer m.RUnlock() defer m.RUnlock()
return m.userMap[usn] return m.userMap[usn]

View File

@@ -8,6 +8,7 @@ import (
"git.hlsq.asia/mmorpg/service-common/net/grpc/grpc_client" "git.hlsq.asia/mmorpg/service-common/net/grpc/grpc_client"
"git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb" "git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb"
"git.hlsq.asia/mmorpg/service-common/proto/ss/ss_pb" "git.hlsq.asia/mmorpg/service-common/proto/ss/ss_pb"
"git.hlsq.asia/mmorpg/service-common/utils"
"git.hlsq.asia/mmorpg/service-gateway/internal/global" "git.hlsq.asia/mmorpg/service-gateway/internal/global"
"git.hlsq.asia/mmorpg/service-gateway/internal/handler/ws_handler/client" "git.hlsq.asia/mmorpg/service-gateway/internal/handler/ws_handler/client"
"sync" "sync"
@@ -152,7 +153,9 @@ func (l *Login) StartLogin(user *User) {
// CheckToken 校验Token是否有效 // CheckToken 校验Token是否有效
func (l *Login) CheckToken(user *User) bool { func (l *Login) CheckToken(user *User) bool {
return redis.GetClient().Get(l.ctx, fmt.Sprintf(global.KeyGatewayAccessToken, user.Cli.USN)).Val() == user.Token usn, _ := redis.GetClient().HGet(context.Background(), global.KeyGatewayAccessToken+user.Token, (&utils.UserSession{}).GetUsnKey()).Int64()
user.Cli.SetUSN(usn)
return usn > 0
} }
// CheckOnline 校验是否在线 // CheckOnline 校验是否在线
@@ -161,7 +164,7 @@ func (l *Login) CheckOnline(user *User) string {
} }
// KickUser 把玩家踢下线 // KickUser 把玩家踢下线
func (l *Login) KickUser(gatewaySID string, usn string) bool { func (l *Login) KickUser(gatewaySID int64, usn int64) bool {
gc, err := grpc_client.GatewayNewClient(gatewaySID) gc, err := grpc_client.GatewayNewClient(gatewaySID)
if err != nil { if err != nil {
log.Errorf("KickUser cannot find gateway client: %v, sid: %v", err, gatewaySID) log.Errorf("KickUser cannot find gateway client: %v, sid: %v", err, gatewaySID)

View File

@@ -78,7 +78,7 @@ func (q *QueueUp) Dequeue() (*client.Client, error) {
} }
// GetPosition 返回用户前面还有多少人在排队 // GetPosition 返回用户前面还有多少人在排队
func (q *QueueUp) GetPosition(usn string) (int64, bool) { func (q *QueueUp) GetPosition(usn int64) (int64, bool) {
val, ok := q.waiting.Load(usn) val, ok := q.waiting.Load(usn)
if !ok { if !ok {
return 0, false return 0, false
@@ -88,7 +88,7 @@ func (q *QueueUp) GetPosition(usn string) (int64, bool) {
} }
// RemoveUser 安全移除用户(标记为取消) // RemoveUser 安全移除用户(标记为取消)
func (q *QueueUp) RemoveUser(usn string) bool { func (q *QueueUp) RemoveUser(usn int64) bool {
_, loaded := q.waiting.LoadAndDelete(usn) _, loaded := q.waiting.LoadAndDelete(usn)
return loaded return loaded
} }

View File

@@ -2,9 +2,10 @@ package http_gateway
import ( import (
"fmt" "fmt"
"git.hlsq.asia/mmorpg/service-common/db/redis"
"git.hlsq.asia/mmorpg/service-common/net/http/http_resp" "git.hlsq.asia/mmorpg/service-common/net/http/http_resp"
"git.hlsq.asia/mmorpg/service-common/utils" "git.hlsq.asia/mmorpg/service-common/utils"
"git.hlsq.asia/mmorpg/service-gateway/config" "git.hlsq.asia/mmorpg/service-gateway/internal/global"
"github.com/gin-contrib/cors" "github.com/gin-contrib/cors"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"go.uber.org/zap" "go.uber.org/zap"
@@ -63,17 +64,18 @@ func authJwt() gin.HandlerFunc {
c.Abort() c.Abort()
return return
} }
claims, err := utils.ParseToken(token, config.Get().Auth.Secret)
if err != nil { usn, _ := redis.GetClient().HGet(c, global.KeyGatewayAccessToken+token, (&utils.UserSession{}).GetUsnKey()).Int64()
if usn == 0 {
http_resp.JsonUnauthorized(c) http_resp.JsonUnauthorized(c)
c.Abort() c.Abort()
return return
} }
// 这里将Header写到请求中grpc-gateway框架会读取然后传给grpc服务 // 这里将Header写到请求中grpc-gateway框架会读取然后传给grpc服务
c.Request.Header.Set("X-Usn", claims.USN) c.Request.Header.Set("X-Usn", utils.Int64ToString(usn))
// 这里写到上下文中,打日志 // 这里写到上下文中,打日志
c.Set("usn", claims.USN) c.Set("usn", usn)
c.Next() c.Next()
} }
} }

View File

@@ -14,6 +14,7 @@ import (
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime" "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin" "go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin"
"google.golang.org/protobuf/encoding/protojson" "google.golang.org/protobuf/encoding/protojson"
"strings"
) )
func InitServeMux() *runtime.ServeMux { func InitServeMux() *runtime.ServeMux {
@@ -49,7 +50,13 @@ func InitRouter() *gin.Engine {
gin.Recovery(), gin.Recovery(),
ginLogger(log.GetLogger().Named("GIN")), ginLogger(log.GetLogger().Named("GIN")),
cors.New(corsConfig()), cors.New(corsConfig()),
otelgin.Middleware(common.KeyDiscoverServiceNameGateway), otelgin.Middleware(
common.KeyDiscoverServiceNameGateway,
otelgin.WithSpanNameFormatter(func(c *gin.Context) string {
method := strings.ToUpper(c.Request.Method)
return method + " " + c.Request.URL.Path
}),
),
) )
r.HandleMethodNotAllowed = true r.HandleMethodNotAllowed = true
@@ -66,7 +73,7 @@ func InitRouter() *gin.Engine {
auth.Use(authJwt()) auth.Use(authJwt())
// 网关 // 网关
initBaseRoute(auth) initGatewayPath(auth)
// 用户中心 // 用户中心
initUserPath(auth) initUserPath(auth)
// 奇怪的知识-服务端 // 奇怪的知识-服务端
@@ -75,14 +82,17 @@ func InitRouter() *gin.Engine {
return r return r
} }
func initBaseRoute(r *gin.RouterGroup) { func initGatewayPath(r *gin.RouterGroup) {
g := r.Group("/gw") g := r.Group("/" + common.KeyDiscoverServiceNameGateway)
g.POST("/open/login", http_handler.Login) g.POST("/open/login", http_handler.Login)
g.POST("/open/refresh_token", http_handler.RefreshToken) g.POST("/open/refresh_token", http_handler.RefreshToken)
g.POST("/open/logout", http_handler.Logout)
} }
func initUserPath(r *gin.RouterGroup) { func initUserPath(r *gin.RouterGroup) {
g := r.Group("/user") g := r.Group("/" + common.KeyDiscoverServiceNameUser)
client, err := grpc_client.UserNewClientLB() client, err := grpc_client.UserNewClientLB()
if err != nil { if err != nil {
log.Errorf("get user conn failed: %v", err) log.Errorf("get user conn failed: %v", err)
@@ -99,7 +109,8 @@ func initUserPath(r *gin.RouterGroup) {
} }
func initQgdzsPath(r *gin.RouterGroup) { func initQgdzsPath(r *gin.RouterGroup) {
g := r.Group("/qgdzs") g := r.Group("/" + common.KeyDiscoverServiceNameQgdzs)
client, err := grpc_client.QgdzsNewClientLB() client, err := grpc_client.QgdzsNewClientLB()
if err != nil { if err != nil {
log.Errorf("get qgdzs conn failed: %v", err) log.Errorf("get qgdzs conn failed: %v", err)

View File

@@ -4,8 +4,6 @@ import (
"fmt" "fmt"
"git.hlsq.asia/mmorpg/service-common/log" "git.hlsq.asia/mmorpg/service-common/log"
"git.hlsq.asia/mmorpg/service-common/net/socket" "git.hlsq.asia/mmorpg/service-common/net/socket"
"git.hlsq.asia/mmorpg/service-common/utils"
"git.hlsq.asia/mmorpg/service-gateway/config"
"git.hlsq.asia/mmorpg/service-gateway/internal/handler/ws_handler/client" "git.hlsq.asia/mmorpg/service-gateway/internal/handler/ws_handler/client"
"git.hlsq.asia/mmorpg/service-gateway/internal/handler/ws_handler/login" "git.hlsq.asia/mmorpg/service-gateway/internal/handler/ws_handler/login"
"go.uber.org/zap" "go.uber.org/zap"
@@ -27,16 +25,11 @@ func (g *GatewayWsServer) OnHandShake(conn socket.ISocketConn) socket.Action {
g.logger.Warnf("token is invalid") g.logger.Warnf("token is invalid")
return socket.Close return socket.Close
} }
claims, err := utils.ParseToken(token, config.Get().Auth.Secret)
if err != nil {
g.logger.Warnf("token is invalid")
return socket.Close
}
cli := client.NewClient(claims.USN, conn) cli := client.NewClient(conn)
conn.SetParam("client", cli) conn.SetParam("client", cli)
if !login.GetLoginQueue().AddToLoginQueue(&login.User{Cli: cli, Token: token}) { if !login.GetLoginQueue().AddToLoginQueue(&login.User{Cli: cli, Token: token}) {
g.logger.Warnf("AddToLoginQueue err, login queue full, usn: %v", claims.USN) g.logger.Warnf("AddToLoginQueue err, login queue full")
return socket.Close return socket.Close
} }
return socket.None return socket.None
@@ -44,7 +37,7 @@ func (g *GatewayWsServer) OnHandShake(conn socket.ISocketConn) socket.Action {
func (g *GatewayWsServer) OnMessage(conn socket.ISocketConn, bytes []byte) socket.Action { func (g *GatewayWsServer) OnMessage(conn socket.ISocketConn, bytes []byte) socket.Action {
cli, ok := conn.GetParam("client").(*client.Client) cli, ok := conn.GetParam("client").(*client.Client)
if !ok || cli.USN == "" || cli.Status != 1 { if !ok || cli.USN == 0 || cli.Status != 1 {
return socket.Close return socket.Close
} }
cli.OnEvent(&client.ClientEvent{Msg: bytes}) cli.OnEvent(&client.ClientEvent{Msg: bytes})
@@ -53,7 +46,7 @@ func (g *GatewayWsServer) OnMessage(conn socket.ISocketConn, bytes []byte) socke
func (g *GatewayWsServer) OnPong(conn socket.ISocketConn) { func (g *GatewayWsServer) OnPong(conn socket.ISocketConn) {
cli, ok := conn.GetParam("client").(*client.Client) cli, ok := conn.GetParam("client").(*client.Client)
if !ok || cli.USN == "" { if !ok || cli.USN == 0 {
return return
} }
cli.OnEvent(&client.PongEvent{}) cli.OnEvent(&client.PongEvent{})

View File

@@ -28,7 +28,6 @@ func (ts *TestSuite) SetupSuite() {
}, },
}, },
Auth: &config.AuthConfig{ Auth: &config.AuthConfig{
Secret: "test",
ShortExpire: 15, ShortExpire: 15,
LongExpire: 10080, LongExpire: 10080,
}, },

View File

@@ -3,11 +3,15 @@ package main
import ( import (
"fmt" "fmt"
"git.hlsq.asia/mmorpg/service-gateway/app" "git.hlsq.asia/mmorpg/service-gateway/app"
"git.hlsq.asia/mmorpg/service-gateway/config"
"github.com/judwhite/go-svc" "github.com/judwhite/go-svc"
"syscall" "syscall"
) )
func main() { func main() {
if err := config.LoadConfig(); err != nil {
fmt.Println(err)
}
if err := svc.Run(&app.Program{}, syscall.SIGINT, syscall.SIGTERM, syscall.SIGKILL); err != nil { if err := svc.Run(&app.Program{}, syscall.SIGINT, syscall.SIGTERM, syscall.SIGKILL); err != nil {
fmt.Println(err) fmt.Println(err)
} }