fusenapi/server/shopping-cart/internal/svc/servicecontext.go

38 lines
1.1 KiB
Go
Raw Normal View History

2023-09-13 09:33:58 +00:00
package svc
import (
"fusenapi/initalize"
"fusenapi/model/gmodel"
"fusenapi/server/shopping-cart/internal/config"
2023-09-20 07:21:42 +00:00
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
2023-09-13 09:33:58 +00:00
"gorm.io/gorm"
)
type ServiceContext struct {
2023-09-20 07:21:42 +00:00
Config config.Config
MysqlConn *gorm.DB
AllModels *gmodel.AllModelsGen
RabbitMq *initalize.RabbitMqHandle
Repositories *initalize.Repositories
2023-09-13 09:33:58 +00:00
}
func NewServiceContext(c config.Config) *ServiceContext {
conn := initalize.InitMysql(c.SourceMysql)
2023-09-20 07:21:42 +00:00
config := aws.Config{
Credentials: credentials.NewStaticCredentials(c.AWS.S3.Credentials.AccessKeyID, c.AWS.S3.Credentials.Secret, c.AWS.S3.Credentials.Token),
}
2023-09-13 09:33:58 +00:00
return &ServiceContext{
Config: c,
MysqlConn: conn,
AllModels: gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)),
RabbitMq: initalize.InitRabbitMq(c.SourceRabbitMq, nil),
2023-09-20 07:21:42 +00:00
Repositories: initalize.NewAllRepositories(&initalize.NewAllRepositorieData{
GormDB: conn,
BLMServiceUrl: &c.BLMService.Url,
AwsSession: session.Must(session.NewSession(&config)),
}),
2023-09-13 09:33:58 +00:00
}
}