fix: some api bug
This commit is contained in:
+31
-14
@@ -6,23 +6,40 @@ Prometheus:
|
||||
Port: 4001
|
||||
Path: /metrics
|
||||
|
||||
DB:
|
||||
Master: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@user-db-rw.juwan:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
||||
Slaves: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@user-db-ro.juwan:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
||||
|
||||
# ===== PROC CONF =====
|
||||
#DB:
|
||||
# Master: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@user-db-rw.juwan:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
||||
# Slaves: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@user-db-ro.juwan:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
||||
#
|
||||
#
|
||||
#SnowflakeRpcConf:
|
||||
# Target: k8s://juwan/snowflake-svc:8080
|
||||
#
|
||||
#CacheConf:
|
||||
# - Host: "${REDIS_M_HOST}"
|
||||
# Type: node
|
||||
# Pass: "${REDIS_PASSWORD}"
|
||||
# User: "default"
|
||||
# - Host: "${REDIS_S_HOST}"
|
||||
# Type: node
|
||||
# Pass: "${REDIS_PASSWORD}"
|
||||
# User: "default"
|
||||
#
|
||||
#Log:
|
||||
# Level: info
|
||||
|
||||
# ===== DEV CONF =====
|
||||
SnowflakeRpcConf:
|
||||
Target: k8s://juwan/snowflake-svc:8080
|
||||
|
||||
Endpoints:
|
||||
- snowflake:8080
|
||||
|
||||
DB:
|
||||
Master: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@postgres:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
||||
Slaves: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@postgres:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
||||
|
||||
CacheConf:
|
||||
- Host: "${REDIS_M_HOST}"
|
||||
- Host: "${REDIS_HOST}:${REDIS_PORT}"
|
||||
Type: node
|
||||
Pass: "${REDIS_PASSWORD}"
|
||||
User: "default"
|
||||
- Host: "${REDIS_S_HOST}"
|
||||
Type: node
|
||||
Pass: "${REDIS_PASSWORD}"
|
||||
User: "default"
|
||||
|
||||
Log:
|
||||
Level: info
|
||||
Level: debug
|
||||
|
||||
@@ -37,7 +37,7 @@ func (l *AddGamesLogic) AddGames(in *pb.AddGamesReq) (*pb.AddGamesResp, error) {
|
||||
SetName(in.Name).
|
||||
SetIcon(in.Icon).
|
||||
SetCategory(in.Category).
|
||||
SetSortOrder(int(in.SortOrder)).
|
||||
SetSortOrder(0).
|
||||
Save(l.ctx)
|
||||
if err != nil {
|
||||
logx.Errorf("AddGamesLogic.addGames err:%v", err)
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"juwan-backend/app/game/rpc/internal/svc"
|
||||
"juwan-backend/app/game/rpc/pb"
|
||||
|
||||
"ariga.io/entcache"
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
@@ -25,14 +26,19 @@ func NewSearchGamesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Searc
|
||||
}
|
||||
|
||||
func (l *SearchGamesLogic) SearchGames(in *pb.SearchGamesReq) (*pb.SearchGamesResp, error) {
|
||||
notFoundErr := entcache.ErrNotFound
|
||||
if in.Page <= 0 || in.Limit <= 0 || in.Page > 1000 || in.Limit > 100 {
|
||||
return nil, errors.New("invalid pagination parameters")
|
||||
}
|
||||
all, err := l.svcCtx.GameModelRO.Games.Query().Limit(int(in.Limit)).Offset(int(in.Limit * (in.Page - 1))).All(l.ctx)
|
||||
if err != nil {
|
||||
if err != nil && !errors.As(err, ¬FoundErr) {
|
||||
logx.Errorf("failed to query games: %v", err)
|
||||
return nil, errors.New("failed to query games")
|
||||
}
|
||||
logx.Debugf("games: %v", all)
|
||||
if err != nil {
|
||||
return &pb.SearchGamesResp{}, nil
|
||||
}
|
||||
list := make([]*pb.Games, 0, len(all))
|
||||
for _, v := range all {
|
||||
temp := &pb.Games{}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package svc
|
||||
|
||||
import (
|
||||
stdsql "database/sql"
|
||||
"juwan-backend/app/game/rpc/internal/config"
|
||||
"juwan-backend/app/game/rpc/internal/models"
|
||||
"juwan-backend/app/snowflake/rpc/snowflake"
|
||||
@@ -10,6 +11,7 @@ import (
|
||||
"time"
|
||||
|
||||
"ariga.io/entcache"
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
|
||||
@@ -24,14 +26,16 @@ type ServiceContext struct {
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
RWConn, err := sql.Open("pgx", c.DB.Master)
|
||||
rawRW, err := stdsql.Open("pgx", c.DB.Master)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
ROConn, err := sql.Open("pgx", c.DB.Slaves)
|
||||
rawRO, err := stdsql.Open("pgx", c.DB.Slaves)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
RWConn := sql.OpenDB(dialect.Postgres, rawRW)
|
||||
ROConn := sql.OpenDB(dialect.Postgres, rawRO)
|
||||
|
||||
redisCluster, err := redisx.ConnectMasterSlaveCluster(c.CacheConf, 5*time.Second)
|
||||
if redisCluster == nil || err != nil {
|
||||
|
||||
Reference in New Issue
Block a user