Refactor: Remove deprecated gRPC service files and implement new API structure
- Deleted old gRPC service definitions in `game_grpc.pb.go` and `public.go`. - Added new API server implementations for objectstory, player, and shop services. - Introduced configuration files for new APIs in `etc/*.yaml`. - Created main entry points for each service in `objectstory.go`, `player.go`, and `shop.go`. - Removed unused user update handler and user API files. - Added utility functions for context management and HTTP header parsing. - Introduced PostgreSQL backup configuration in `backup/postgreSql.yaml`.
This commit is contained in:
@@ -42,17 +42,26 @@ func (l *AddShopsLogic) AddShops(in *pb.AddShopsReq) (*pb.AddShopsResp, error) {
|
||||
return nil, errors.New("invalid template config")
|
||||
}
|
||||
|
||||
rating, err := decimal.NewFromString(in.Rating)
|
||||
if err != nil {
|
||||
return nil, errors.New("invalid rating")
|
||||
}
|
||||
commissionValue, err := decimal.NewFromString(in.CommissionValue)
|
||||
if err != nil {
|
||||
return nil, errors.New("invalid commissionValue")
|
||||
}
|
||||
|
||||
_, err = l.svcCtx.ShopModelRO.Shops.Create().
|
||||
SetID(idResp.Id).
|
||||
SetOwnerID(in.OwnerId).
|
||||
SetName(in.Name).
|
||||
SetBanner(in.Banner).
|
||||
SetDescription(in.Description).
|
||||
SetRating(decimal.NewFromFloat(in.Rating)).
|
||||
SetRating(rating).
|
||||
SetTotalOrders(int(in.TotalOrders)).
|
||||
SetPlayerCount(int(in.PlayerCount)).
|
||||
SetNillableCommissionType(&in.CommissionType).
|
||||
SetCommissionValue(decimal.NewFromFloat(in.CommissionValue)).
|
||||
SetCommissionValue(commissionValue).
|
||||
SetAllowMultiShop(in.AllowMultiShop).
|
||||
SetAllowIndependentOrders(in.AllowIndependentOrders).
|
||||
SetDispatchMode(in.DispatchMode).
|
||||
|
||||
@@ -43,11 +43,11 @@ func (l *GetShopsByIdLogic) GetShopsById(in *pb.GetShopsByIdReq) (*pb.GetShopsBy
|
||||
Id: shop.ID,
|
||||
OwnerId: shop.OwnerID,
|
||||
Name: shop.Name,
|
||||
Rating: shop.Rating.InexactFloat64(),
|
||||
Rating: shop.Rating.String(),
|
||||
TotalOrders: int64(shop.TotalOrders),
|
||||
PlayerCount: int64(shop.PlayerCount),
|
||||
CommissionType: shop.CommissionType,
|
||||
CommissionValue: shop.CommissionValue.InexactFloat64(),
|
||||
CommissionValue: shop.CommissionValue.String(),
|
||||
AllowMultiShop: shop.AllowMultiShop,
|
||||
AllowIndependentOrders: shop.AllowIndependentOrders,
|
||||
DispatchMode: shop.DispatchMode,
|
||||
|
||||
@@ -2,8 +2,12 @@ package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"juwan-backend/app/shop/rpc/internal/models/predicate"
|
||||
"juwan-backend/app/shop/rpc/internal/models/shopinvitations"
|
||||
"juwan-backend/app/shop/rpc/internal/svc"
|
||||
"juwan-backend/app/shop/rpc/pb"
|
||||
"time"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
@@ -23,6 +27,65 @@ func NewSearchShopInvitationsLogic(ctx context.Context, svcCtx *svc.ServiceConte
|
||||
}
|
||||
|
||||
func (l *SearchShopInvitationsLogic) SearchShopInvitations(in *pb.SearchShopInvitationsReq) (*pb.SearchShopInvitationsResp, error) {
|
||||
// TODO: implement search logic based on the provided criteria in the request
|
||||
return &pb.SearchShopInvitationsResp{}, nil
|
||||
if in.Limit <= 0 {
|
||||
in.Limit = 20
|
||||
}
|
||||
if in.Limit > 1000 {
|
||||
return nil, errors.New("limit too large")
|
||||
}
|
||||
|
||||
preds := make([]predicate.ShopInvitations, 0, 8)
|
||||
if in.Id > 0 {
|
||||
preds = append(preds, shopinvitations.IDEQ(in.Id))
|
||||
}
|
||||
if in.ShopId > 0 {
|
||||
preds = append(preds, shopinvitations.ShopIDEQ(in.ShopId))
|
||||
}
|
||||
if in.PlayerId > 0 {
|
||||
preds = append(preds, shopinvitations.PlayerIDEQ(in.PlayerId))
|
||||
}
|
||||
if in.Status != "" {
|
||||
preds = append(preds, shopinvitations.StatusEQ(in.Status))
|
||||
}
|
||||
if in.InvitedBy > 0 {
|
||||
preds = append(preds, shopinvitations.InvitedByEQ(in.InvitedBy))
|
||||
}
|
||||
if in.CreatedAt > 0 {
|
||||
preds = append(preds, shopinvitations.CreatedAtGTE(time.Unix(in.CreatedAt, 0)))
|
||||
}
|
||||
if in.RespondedAt > 0 {
|
||||
preds = append(preds, shopinvitations.RespondedAtGTE(time.Unix(in.RespondedAt, 0)))
|
||||
}
|
||||
|
||||
query := l.svcCtx.ShopModelRO.ShopInvitations.Query()
|
||||
if len(preds) > 0 {
|
||||
query = query.Where(shopinvitations.And(preds...))
|
||||
}
|
||||
|
||||
list, err := query.
|
||||
Offset(int(in.Page * in.Limit)).
|
||||
Limit(int(in.Limit)).
|
||||
All(l.ctx)
|
||||
if err != nil {
|
||||
logx.Errorf("search shop invitations failed, %s", err.Error())
|
||||
return nil, errors.New("search shop invitations failed")
|
||||
}
|
||||
|
||||
result := make([]*pb.ShopInvitations, 0, len(list))
|
||||
for _, item := range list {
|
||||
pbItem := &pb.ShopInvitations{
|
||||
Id: item.ID,
|
||||
ShopId: item.ShopID,
|
||||
PlayerId: item.PlayerID,
|
||||
Status: item.Status,
|
||||
InvitedBy: item.InvitedBy,
|
||||
CreatedAt: item.CreatedAt.Unix(),
|
||||
}
|
||||
if item.RespondedAt != nil {
|
||||
pbItem.RespondedAt = item.RespondedAt.Unix()
|
||||
}
|
||||
result = append(result, pbItem)
|
||||
}
|
||||
|
||||
return &pb.SearchShopInvitationsResp{ShopInvitations: result}, nil
|
||||
}
|
||||
|
||||
@@ -2,7 +2,12 @@ package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"juwan-backend/app/shop/rpc/internal/models/predicate"
|
||||
"juwan-backend/app/shop/rpc/internal/models/shopplayers"
|
||||
"juwan-backend/app/shop/rpc/internal/svc"
|
||||
"juwan-backend/app/shop/rpc/pb"
|
||||
"time"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
@@ -22,5 +27,57 @@ func NewSearchShopPlayersLogic(ctx context.Context, svcCtx *svc.ServiceContext)
|
||||
}
|
||||
|
||||
func (l *SearchShopPlayersLogic) SearchShopPlayers(in *pb.SearchShopPlayersReq) (*pb.SearchShopPlayersResp, error) {
|
||||
if in.Limit <= 0 {
|
||||
in.Limit = 20
|
||||
}
|
||||
if in.Limit > 1000 {
|
||||
return nil, errors.New("limit too large")
|
||||
}
|
||||
|
||||
preds := make([]predicate.ShopPlayers, 0, 8)
|
||||
if in.ShopId > 0 {
|
||||
preds = append(preds, shopplayers.ShopIDEQ(in.ShopId))
|
||||
}
|
||||
if in.PlayerId > 0 {
|
||||
preds = append(preds, shopplayers.PlayerIDEQ(in.PlayerId))
|
||||
}
|
||||
if in.IsPrimary {
|
||||
preds = append(preds, shopplayers.IsPrimaryEQ(true))
|
||||
}
|
||||
if in.JoinedAt > 0 {
|
||||
preds = append(preds, shopplayers.JoinedAtGTE(time.Unix(in.JoinedAt, 0)))
|
||||
}
|
||||
if in.LeftAt > 0 {
|
||||
preds = append(preds, shopplayers.LeftAtGTE(time.Unix(in.LeftAt, 0)))
|
||||
}
|
||||
|
||||
query := l.svcCtx.ShopModelRO.ShopPlayers.Query()
|
||||
if len(preds) > 0 {
|
||||
query = query.Where(shopplayers.And(preds...))
|
||||
}
|
||||
|
||||
list, err := query.
|
||||
Offset(int(in.Page * in.Limit)).
|
||||
Limit(int(in.Limit)).
|
||||
All(l.ctx)
|
||||
if err != nil {
|
||||
logx.Errorf("search shop players failed, %s", err.Error())
|
||||
return nil, errors.New("search shop players failed")
|
||||
}
|
||||
|
||||
result := make([]*pb.ShopPlayers, 0, len(list))
|
||||
for _, item := range list {
|
||||
pbItem := &pb.ShopPlayers{
|
||||
ShopId: item.ShopID,
|
||||
PlayerId: item.PlayerID,
|
||||
IsPrimary: item.IsPrimary,
|
||||
JoinedAt: item.JoinedAt.Unix(),
|
||||
}
|
||||
if item.LeftAt != nil {
|
||||
pbItem.LeftAt = item.LeftAt.Unix()
|
||||
}
|
||||
result = append(result, pbItem)
|
||||
}
|
||||
|
||||
return &pb.SearchShopPlayersResp{ShopPlayers: result}, nil
|
||||
}
|
||||
|
||||
@@ -2,9 +2,17 @@ package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"juwan-backend/app/shop/rpc/internal/models/predicate"
|
||||
"juwan-backend/app/shop/rpc/internal/models/shops"
|
||||
"time"
|
||||
|
||||
"juwan-backend/app/shop/rpc/internal/svc"
|
||||
"juwan-backend/app/shop/rpc/pb"
|
||||
|
||||
"encoding/json"
|
||||
|
||||
"github.com/shopspring/decimal"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
@@ -23,5 +31,112 @@ func NewSearchShopsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Searc
|
||||
}
|
||||
|
||||
func (l *SearchShopsLogic) SearchShops(in *pb.SearchShopsReq) (*pb.SearchShopsResp, error) {
|
||||
if in.Limit <= 0 {
|
||||
in.Limit = 20
|
||||
}
|
||||
if in.Limit > 1000 {
|
||||
return nil, errors.New("limit too large")
|
||||
}
|
||||
|
||||
preds := make([]predicate.Shops, 0, 12)
|
||||
if in.Id > 0 {
|
||||
preds = append(preds, shops.IDEQ(in.Id))
|
||||
}
|
||||
if in.OwnerId > 0 {
|
||||
preds = append(preds, shops.OwnerIDEQ(in.OwnerId))
|
||||
}
|
||||
if in.Name != "" {
|
||||
preds = append(preds, shops.NameContainsFold(in.Name))
|
||||
}
|
||||
if in.Description != "" {
|
||||
preds = append(preds, shops.DescriptionContainsFold(in.Description))
|
||||
}
|
||||
if in.CommissionType != "" {
|
||||
preds = append(preds, shops.CommissionTypeEQ(in.CommissionType))
|
||||
}
|
||||
if in.DispatchMode != "" {
|
||||
preds = append(preds, shops.DispatchModeEQ(in.DispatchMode))
|
||||
}
|
||||
if in.Rating != "" {
|
||||
rating, perr := decimal.NewFromString(in.Rating)
|
||||
if perr != nil {
|
||||
return nil, errors.New("invalid rating")
|
||||
}
|
||||
preds = append(preds, shops.RatingGTE(rating))
|
||||
}
|
||||
if in.CommissionValue != "" {
|
||||
commissionValue, perr := decimal.NewFromString(in.CommissionValue)
|
||||
if perr != nil {
|
||||
return nil, errors.New("invalid commissionValue")
|
||||
}
|
||||
preds = append(preds, shops.CommissionValueGTE(commissionValue))
|
||||
}
|
||||
if in.TotalOrders > 0 {
|
||||
preds = append(preds, shops.TotalOrdersGTE(int(in.TotalOrders)))
|
||||
}
|
||||
if in.PlayerCount > 0 {
|
||||
preds = append(preds, shops.PlayerCountGTE(int(in.PlayerCount)))
|
||||
}
|
||||
if in.AllowMultiShop {
|
||||
preds = append(preds, shops.AllowMultiShopEQ(true))
|
||||
}
|
||||
if in.AllowIndependentOrders {
|
||||
preds = append(preds, shops.AllowIndependentOrdersEQ(true))
|
||||
}
|
||||
if in.CreatedAt > 0 {
|
||||
preds = append(preds, shops.CreatedAtGTE(time.Unix(in.CreatedAt, 0)))
|
||||
}
|
||||
if in.UpdatedAt > 0 {
|
||||
preds = append(preds, shops.UpdatedAtGTE(time.Unix(in.UpdatedAt, 0)))
|
||||
}
|
||||
|
||||
query := l.svcCtx.ShopModelRO.Shops.Query()
|
||||
if len(preds) > 0 {
|
||||
query = query.Where(shops.And(preds...))
|
||||
}
|
||||
|
||||
list, err := query.
|
||||
Offset(int(in.Page * in.Limit)).
|
||||
Limit(int(in.Limit)).
|
||||
All(l.ctx)
|
||||
if err != nil {
|
||||
logx.Errorf("search shops failed, %s", err.Error())
|
||||
return nil, errors.New("search shops failed")
|
||||
}
|
||||
|
||||
result := make([]*pb.Shops, 0, len(list))
|
||||
for _, item := range list {
|
||||
templateConfigBytes, err := json.Marshal(item.TemplateConfig)
|
||||
if err != nil {
|
||||
logx.WithContext(l.ctx).Errorf("marshal template config failed: %v", err)
|
||||
continue
|
||||
}
|
||||
|
||||
pbItem := &pb.Shops{
|
||||
Id: item.ID,
|
||||
OwnerId: item.OwnerID,
|
||||
Name: item.Name,
|
||||
Rating: item.Rating.String(),
|
||||
TotalOrders: int64(item.TotalOrders),
|
||||
PlayerCount: int64(item.PlayerCount),
|
||||
CommissionType: item.CommissionType,
|
||||
CommissionValue: item.CommissionValue.String(),
|
||||
AllowMultiShop: item.AllowMultiShop,
|
||||
AllowIndependentOrders: item.AllowIndependentOrders,
|
||||
DispatchMode: item.DispatchMode,
|
||||
Announcements: item.Announcements,
|
||||
TemplateConfig: string(templateConfigBytes),
|
||||
CreatedAt: item.CreatedAt.Unix(),
|
||||
UpdatedAt: item.UpdatedAt.Unix(),
|
||||
}
|
||||
if item.Banner != nil {
|
||||
pbItem.Banner = *item.Banner
|
||||
}
|
||||
if item.Description != nil {
|
||||
pbItem.Description = *item.Description
|
||||
}
|
||||
result = append(result, pbItem)
|
||||
}
|
||||
|
||||
return &pb.SearchShopsResp{Shops: result}, nil
|
||||
}
|
||||
|
||||
@@ -3,11 +3,11 @@ package logic
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"juwan-backend/app/shop/rpc/internal/models/shopinvitations"
|
||||
"juwan-backend/app/shop/rpc/internal/svc"
|
||||
"juwan-backend/app/shop/rpc/pb"
|
||||
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
@@ -26,5 +26,19 @@ func NewUpdateShopInvitationsLogic(ctx context.Context, svcCtx *svc.ServiceConte
|
||||
}
|
||||
|
||||
func (l *UpdateShopInvitationsLogic) UpdateShopInvitations(in *pb.UpdateShopInvitationsReq) (*pb.UpdateShopInvitationsResp, error) {
|
||||
update, err := l.svcCtx.ShopModelRW.ShopInvitations.UpdateOneID(in.Id).
|
||||
Where(shopinvitations.PlayerIDEQ(in.PlayerId)).
|
||||
SetStatus(in.Status).Save(l.ctx)
|
||||
if err != nil {
|
||||
logx.Errorf("failed to update shop invitation: %v", err)
|
||||
return nil, errors.New("failed to update shop invitation")
|
||||
}
|
||||
|
||||
resp := &pb.ShopInvitations{}
|
||||
err = copier.Copy(resp, update)
|
||||
if err != nil {
|
||||
logx.Errorf("failed to copy update: %v", err)
|
||||
return nil, errors.New("failed to update shop invitation")
|
||||
}
|
||||
return &pb.UpdateShopInvitationsResp{ShopInvitations: resp}, nil
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package logic
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"juwan-backend/app/shop/rpc/internal/models"
|
||||
"juwan-backend/app/shop/rpc/internal/models/predicate"
|
||||
"juwan-backend/app/shop/rpc/internal/models/shopplayers"
|
||||
"time"
|
||||
|
||||
@@ -28,5 +28,32 @@ func NewUpdateShopPlayersLogic(ctx context.Context, svcCtx *svc.ServiceContext)
|
||||
}
|
||||
|
||||
func (l *UpdateShopPlayersLogic) UpdateShopPlayers(in *pb.UpdateShopPlayersReq) (*pb.UpdateShopPlayersResp, error) {
|
||||
if in.ShopId <= 0 || in.PlayerId <= 0 {
|
||||
return nil, errors.New("invalid shop_id or player_id")
|
||||
}
|
||||
|
||||
preds := []predicate.ShopPlayers{
|
||||
shopplayers.ShopIDEQ(in.ShopId),
|
||||
shopplayers.PlayerIDEQ(in.PlayerId),
|
||||
}
|
||||
|
||||
updater := l.svcCtx.ShopModelRW.ShopPlayers.Update().
|
||||
Where(shopplayers.And(preds...)).
|
||||
SetIsPrimary(in.IsPrimary)
|
||||
|
||||
if in.LeftAt > 0 {
|
||||
t := time.Unix(in.LeftAt, 0)
|
||||
updater = updater.SetLeftAt(t)
|
||||
}
|
||||
|
||||
affected, err := updater.Save(l.ctx)
|
||||
if err != nil {
|
||||
logx.Errorf("update shop players failed, %s", err.Error())
|
||||
return nil, errors.New("update shop players failed")
|
||||
}
|
||||
if affected == 0 {
|
||||
return nil, errors.New("shop player not found")
|
||||
}
|
||||
|
||||
return &pb.UpdateShopPlayersResp{}, nil
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"juwan-backend/app/shop/rpc/internal/models/shops"
|
||||
"time"
|
||||
|
||||
"juwan-backend/app/shop/rpc/internal/svc"
|
||||
@@ -28,5 +29,74 @@ func NewUpdateShopsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Updat
|
||||
}
|
||||
|
||||
func (l *UpdateShopsLogic) UpdateShops(in *pb.UpdateShopsReq) (*pb.UpdateShopsResp, error) {
|
||||
updater := l.svcCtx.ShopModelRW.Shops.UpdateOneID(in.Id)
|
||||
|
||||
if in.OwnerId > 0 {
|
||||
updater = updater.SetOwnerID(in.OwnerId)
|
||||
}
|
||||
if in.Name != "" {
|
||||
updater = updater.SetName(in.Name)
|
||||
}
|
||||
if in.Banner != "" {
|
||||
updater = updater.SetBanner(in.Banner)
|
||||
}
|
||||
if in.Description != "" {
|
||||
updater = updater.SetDescription(in.Description)
|
||||
}
|
||||
if in.Rating != "" {
|
||||
rating, perr := decimal.NewFromString(in.Rating)
|
||||
if perr != nil {
|
||||
return nil, errors.New("invalid rating")
|
||||
}
|
||||
updater = updater.SetRating(rating)
|
||||
}
|
||||
if in.TotalOrders > 0 {
|
||||
updater = updater.SetTotalOrders(int(in.TotalOrders))
|
||||
}
|
||||
if in.PlayerCount > 0 {
|
||||
updater = updater.SetPlayerCount(int(in.PlayerCount))
|
||||
}
|
||||
if in.CommissionType != "" {
|
||||
updater = updater.SetCommissionType(in.CommissionType)
|
||||
}
|
||||
if in.CommissionValue != "" {
|
||||
commissionValue, perr := decimal.NewFromString(in.CommissionValue)
|
||||
if perr != nil {
|
||||
return nil, errors.New("invalid commissionValue")
|
||||
}
|
||||
updater = updater.SetCommissionValue(commissionValue)
|
||||
}
|
||||
if in.DispatchMode != "" {
|
||||
updater = updater.SetDispatchMode(in.DispatchMode)
|
||||
}
|
||||
|
||||
updater = updater.
|
||||
SetAllowMultiShop(in.AllowMultiShop).
|
||||
SetAllowIndependentOrders(in.AllowIndependentOrders)
|
||||
|
||||
if len(in.Announcements) > 0 {
|
||||
updater = updater.SetAnnouncements(in.Announcements)
|
||||
}
|
||||
|
||||
if in.TemplateConfig != "" {
|
||||
var templateConfig map[string]interface{}
|
||||
err := json.Unmarshal([]byte(in.TemplateConfig), &templateConfig)
|
||||
if err != nil {
|
||||
logx.WithContext(l.ctx).Errorf("invalid template config: %v", err)
|
||||
return nil, errors.New("invalid template config")
|
||||
}
|
||||
updater = updater.SetTemplateConfig(templateConfig)
|
||||
}
|
||||
|
||||
if in.UpdatedAt > 0 {
|
||||
updater = updater.SetUpdatedAt(time.Unix(in.UpdatedAt, 0))
|
||||
}
|
||||
|
||||
_, err := updater.Where(shops.IDEQ(in.Id)).Save(l.ctx)
|
||||
if err != nil {
|
||||
logx.WithContext(l.ctx).Errorf("update shops failed: %v", err)
|
||||
return nil, errors.New("update shops failed")
|
||||
}
|
||||
|
||||
return &pb.UpdateShopsResp{}, nil
|
||||
}
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
package svc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"juwan-backend/app/shop/rpc/internal/config"
|
||||
"juwan-backend/app/shop/rpc/internal/models"
|
||||
"juwan-backend/app/snowflake/rpc/snowflake"
|
||||
"juwan-backend/common/redisx"
|
||||
"juwan-backend/common/snowflakex"
|
||||
"juwan-backend/pkg/adapter"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"ariga.io/entcache"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
_ "github.com/jackc/pgx/v5/stdlib"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
@@ -40,10 +43,22 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
||||
|
||||
RWDrv := entcache.NewDriver(RWConn, entcache.TTL(30*time.Second), entcache.Levels(adapter.NewRedisCache(redisCluster.Client)))
|
||||
RODrv := entcache.NewDriver(ROConn, entcache.TTL(30*time.Second), entcache.Levels(adapter.NewRedisCache(redisCluster.Client)))
|
||||
|
||||
entLogFn := func(v ...any) {
|
||||
logx.Infof("[ent][shop] %s", fmt.Sprint(v...))
|
||||
}
|
||||
|
||||
rwModelOpts := []models.Option{models.Driver(RWDrv), models.Log(entLogFn)}
|
||||
roModelOpts := []models.Option{models.Driver(RODrv), models.Log(entLogFn)}
|
||||
if strings.EqualFold(c.Log.Level, "debug") {
|
||||
rwModelOpts = append(rwModelOpts, models.Debug())
|
||||
roModelOpts = append(roModelOpts, models.Debug())
|
||||
}
|
||||
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
Snowflake: snowflakex.NewClient(c.SnowflakeRpcConf),
|
||||
ShopModelRO: models.NewClient(models.Driver(RODrv)),
|
||||
ShopModelRW: models.NewClient(models.Driver(RWDrv)),
|
||||
ShopModelRO: models.NewClient(roModelOpts...),
|
||||
ShopModelRW: models.NewClient(rwModelOpts...),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user