feat kafka 改版 2
This commit is contained in:
@@ -21,7 +21,7 @@ func (p *Program) Init(_ svc.Environment) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
p.moduleList = append(p.moduleList, base)
|
p.moduleList = append(p.moduleList, base)
|
||||||
p.moduleList = append(p.moduleList, (&module.DB{}).Bind(config.Get().DB))
|
p.moduleList = append(p.moduleList, (&module.DB{}).Bind(config.Get().DB, config.Get().App.Name))
|
||||||
p.moduleList = append(p.moduleList, (&module.Grpc{}).Bind(grpc_server.NewServer(config.Get().Serve.Grpc)))
|
p.moduleList = append(p.moduleList, (&module.Grpc{}).Bind(grpc_server.NewServer(config.Get().Serve.Grpc)))
|
||||||
p.moduleList = append(p.moduleList, (&module.Prometheus{}).Bind(config.Get().Metric))
|
p.moduleList = append(p.moduleList, (&module.Prometheus{}).Bind(config.Get().Metric))
|
||||||
p.moduleList = append(p.moduleList, (&module.Tracer{}).Bind(config.Get().Metric, common.KeyDiscoverServiceNameUser))
|
p.moduleList = append(p.moduleList, (&module.Tracer{}).Bind(config.Get().Metric, common.KeyDiscoverServiceNameUser))
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -3,7 +3,7 @@ module git.hlsq.asia/mmorpg/service-user
|
|||||||
go 1.24.0
|
go 1.24.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.hlsq.asia/mmorpg/service-common v0.0.0-20260125091651-f22d22cbdc57
|
git.hlsq.asia/mmorpg/service-common v0.0.0-20260130025300-427fca7ed19f
|
||||||
github.com/judwhite/go-svc v1.2.1
|
github.com/judwhite/go-svc v1.2.1
|
||||||
google.golang.org/grpc v1.77.0
|
google.golang.org/grpc v1.77.0
|
||||||
gorm.io/gen v0.3.27
|
gorm.io/gen v0.3.27
|
||||||
|
|||||||
4
go.sum
4
go.sum
@@ -1,7 +1,7 @@
|
|||||||
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-20260125091651-f22d22cbdc57 h1:u+BKY8YAm1gA9EL3Tw3KfzKRmZ3TgBMkFQurltLl438=
|
git.hlsq.asia/mmorpg/service-common v0.0.0-20260130025300-427fca7ed19f h1:U0HnB8i3ZTKrg3XBQpwFcI64LB6mraj02yNAqV3MBws=
|
||||||
git.hlsq.asia/mmorpg/service-common v0.0.0-20260125091651-f22d22cbdc57/go.mod h1:mMhZcumphj6gaVTppVYsMTkd+5HupmQgAc53Pd4MH9I=
|
git.hlsq.asia/mmorpg/service-common v0.0.0-20260130025300-427fca7ed19f/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 h1:njRsX6jNlnR+ClJ8XmkO+CM4unbrNr/2vB5KK6UA+IE=
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package repository
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.hlsq.asia/mmorpg/service-common/db/mysql"
|
"git.hlsq.asia/mmorpg/service-common/db/mysql"
|
||||||
|
"git.hlsq.asia/mmorpg/service-user/internal/dao/query"
|
||||||
)
|
)
|
||||||
|
|
||||||
var dbName mysql.DBName = "user_db"
|
var dbName mysql.DBName = "user_db"
|
||||||
@@ -12,6 +13,10 @@ var (
|
|||||||
userCacheByPhone = "c:user:p:%v"
|
userCacheByPhone = "c:user:p:%v"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func Query() *query.Query {
|
||||||
|
return query.Use(mysql.GetDB(dbName))
|
||||||
|
}
|
||||||
|
|
||||||
func keyCacheBySn(sn string, tableName string) string {
|
func keyCacheBySn(sn string, tableName string) string {
|
||||||
return fmt.Sprintf(cacheBySn, tableName, sn)
|
return fmt.Sprintf(cacheBySn, tableName, sn)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package repository
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"git.hlsq.asia/mmorpg/service-common/db/mysql"
|
|
||||||
"git.hlsq.asia/mmorpg/service-common/db/redis"
|
"git.hlsq.asia/mmorpg/service-common/db/redis"
|
||||||
"git.hlsq.asia/mmorpg/service-user/internal/dao/model"
|
"git.hlsq.asia/mmorpg/service-user/internal/dao/model"
|
||||||
"git.hlsq.asia/mmorpg/service-user/internal/dao/query"
|
"git.hlsq.asia/mmorpg/service-user/internal/dao/query"
|
||||||
@@ -15,10 +14,10 @@ type UserDao struct {
|
|||||||
cache *redis.CacheClient
|
cache *redis.CacheClient
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewUserDao(ctx context.Context, cache ...*redis.CacheClient) *UserDao {
|
func NewUserDao(ctx context.Context, query *query.Query, cache ...*redis.CacheClient) *UserDao {
|
||||||
dao := &UserDao{
|
dao := &UserDao{
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
query: query.Use(mysql.GetDB(dbName)),
|
query: query,
|
||||||
}
|
}
|
||||||
if len(cache) > 0 {
|
if len(cache) > 0 {
|
||||||
dao.cache = cache[0]
|
dao.cache = cache[0]
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (s *Server) PhoneLogin(ctx context.Context, req *grpc_pb.PhoneLoginReq) (*grpc_pb.PhoneLoginResp, error) {
|
func (s *Server) PhoneLogin(ctx context.Context, req *grpc_pb.PhoneLoginReq) (*grpc_pb.PhoneLoginResp, error) {
|
||||||
userDao := repository.NewUserDao(ctx, redis.GetCacheClient())
|
userDao := repository.NewUserDao(ctx, s.query, redis.GetCacheClient())
|
||||||
user, err := userDao.FindByPhone(req.Phone)
|
user, err := userDao.FindByPhone(req.Phone)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
@@ -42,7 +42,7 @@ func (s *Server) WxMiniLogin(ctx context.Context, req *grpc_pb.WxMiniLoginReq) (
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, utils.ErrorsWrap(err)
|
return nil, utils.ErrorsWrap(err)
|
||||||
}
|
}
|
||||||
userDao := repository.NewUserDao(ctx, redis.GetCacheClient())
|
userDao := repository.NewUserDao(ctx, s.query, redis.GetCacheClient())
|
||||||
user, err := userDao.FindByWxUnionIDOrOpenID(session.UnionID, session.OpenID)
|
user, err := userDao.FindByWxUnionIDOrOpenID(session.UnionID, session.OpenID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
@@ -69,7 +69,7 @@ func (s *Server) GetUserInfo(ctx context.Context, req *grpc_pb.GetUserInfoReq) (
|
|||||||
if !utils.ShouldBindUsn(ctx, &req.USN) {
|
if !utils.ShouldBindUsn(ctx, &req.USN) {
|
||||||
return nil, utils.ErrorsWrap(http_resp.ParamError)
|
return nil, utils.ErrorsWrap(http_resp.ParamError)
|
||||||
}
|
}
|
||||||
userDao := repository.NewUserDao(ctx, redis.GetCacheClient())
|
userDao := repository.NewUserDao(ctx, s.query, redis.GetCacheClient())
|
||||||
user, err := userDao.FindBySn(req.USN)
|
user, err := userDao.FindBySn(req.USN)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, utils.ErrorsWrap(err)
|
return nil, utils.ErrorsWrap(err)
|
||||||
|
|||||||
@@ -5,12 +5,15 @@ import (
|
|||||||
"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-user/internal/dao/query"
|
||||||
|
"git.hlsq.asia/mmorpg/service-user/internal/dao/repository"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
grpc_pb.UnimplementedUserServer
|
grpc_pb.UnimplementedUserServer
|
||||||
service.Base
|
service.Base
|
||||||
|
query *query.Query
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServer(cfg *config.GrpcConfig) *Server {
|
func NewServer(cfg *config.GrpcConfig) *Server {
|
||||||
@@ -33,6 +36,7 @@ func (s *Server) OnCustomGrpcServerOption() []grpc.ServerOption {
|
|||||||
|
|
||||||
func (s *Server) OnInit(serve *grpc.Server) {
|
func (s *Server) OnInit(serve *grpc.Server) {
|
||||||
grpc_pb.RegisterUserServer(serve, s)
|
grpc_pb.RegisterUserServer(serve, s)
|
||||||
|
s.query = repository.Query()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) OnClose() {
|
func (s *Server) OnClose() {
|
||||||
|
|||||||
Reference in New Issue
Block a user