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

41 lines
1.2 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-10-10 09:17:28 +00:00
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-22 03:36:10 +00:00
AwsSession *session.Session
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{
2023-09-22 03:36:10 +00:00
Config: c,
MysqlConn: conn,
AllModels: gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)),
RabbitMq: initalize.InitRabbitMq(c.SourceRabbitMq, nil),
AwsSession: session.Must(session.NewSession(&config)),
2023-09-20 07:21:42 +00:00
Repositories: initalize.NewAllRepositories(&initalize.NewAllRepositorieData{
2023-10-10 09:17:28 +00:00
GormDB: conn,
BLMServiceUrls: c.BLMService.Urls,
AwsSession: session.Must(session.NewSession(&config)),
2023-09-20 07:21:42 +00:00
}),
2023-09-13 09:33:58 +00:00
}
}