Files
lone-services/services/product/internal/svc/servicecontext.go
T
2026-10-08 09:25:41 +08:00

48 lines
1.2 KiB
Go

package svc
import (
"lone-services/pkg/utils"
"lone-services/services/product/internal/config"
"github.com/zeromicro/go-zero/core/logx"
"gorm.io/gorm"
)
type ServiceContext struct {
Config config.Config
DB *gorm.DB
Prefix string
ChoreSvcName string
WecomSvcName string
StoreSvcName string
OrderSvcName string
}
func NewServiceContext(c config.Config, db *gorm.DB) *ServiceContext {
choreSvc := utils.GetConfigString("services.chore")
if choreSvc == utils.StringEmpty {
logx.Error("config services.chore empty")
}
wecomSvc := utils.GetConfigString("services.wecom")
if wecomSvc == utils.StringEmpty {
logx.Error("config services.wecom empty")
}
storeSvc := utils.GetConfigString("services.store")
if storeSvc == utils.StringEmpty {
logx.Error("config services.store empty")
}
orderSvc := utils.GetConfigString("services.order")
if orderSvc == utils.StringEmpty {
logx.Error("config services.order empty")
}
return &ServiceContext{
Config: c,
DB: db,
Prefix: utils.GetConfigString("mysql.prefix"),
ChoreSvcName: choreSvc,
WecomSvcName: wecomSvc,
StoreSvcName: storeSvc,
OrderSvcName: orderSvc,
}
}