41 lines
1.2 KiB
Go
41 lines
1.2 KiB
Go
package svc
|
|
|
|
import (
|
|
"fusenapi/initalize"
|
|
"fusenapi/model/gmodel"
|
|
"fusenapi/server/shopping-cart/internal/config"
|
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
|
"github.com/aws/aws-sdk-go/aws/credentials"
|
|
"github.com/aws/aws-sdk-go/aws/session"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type ServiceContext struct {
|
|
Config config.Config
|
|
MysqlConn *gorm.DB
|
|
AllModels *gmodel.AllModelsGen
|
|
RabbitMq *initalize.RabbitMqHandle
|
|
Repositories *initalize.Repositories
|
|
AwsSession *session.Session
|
|
}
|
|
|
|
func NewServiceContext(c config.Config) *ServiceContext {
|
|
conn := initalize.InitMysql(c.SourceMysql)
|
|
config := aws.Config{
|
|
Credentials: credentials.NewStaticCredentials(c.AWS.S3.Credentials.AccessKeyID, c.AWS.S3.Credentials.Secret, c.AWS.S3.Credentials.Token),
|
|
}
|
|
return &ServiceContext{
|
|
Config: c,
|
|
MysqlConn: conn,
|
|
AllModels: gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)),
|
|
RabbitMq: initalize.InitRabbitMq(c.SourceRabbitMq, nil),
|
|
AwsSession: session.Must(session.NewSession(&config)),
|
|
Repositories: initalize.NewAllRepositories(&initalize.NewAllRepositorieData{
|
|
GormDB: conn,
|
|
BLMServiceUrls: c.BLMService.Urls,
|
|
AwsSession: session.Must(session.NewSession(&config)),
|
|
}),
|
|
}
|
|
}
|