package svc import ( "fusenapi/server/order/internal/config" "fusenapi/utils/queue" "fusenapi/initalize" "fusenapi/model/gmodel" "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 Repositories *initalize.Repositories DelayQueue *queue.DelayMessage } func NewServiceContext(c config.Config) *ServiceContext { configAWS := aws.Config{ Credentials: credentials.NewStaticCredentials(c.AWS.S3.Credentials.AccessKeyID, c.AWS.S3.Credentials.Secret, c.AWS.S3.Credentials.Token), } conn := initalize.InitMysql(c.SourceMysql) // delayQueue := initalize.InitDelayMessage() repositories := initalize.NewAllRepositories(&initalize.NewAllRepositorieData{ GormDB: conn, AwsSession: session.Must(session.NewSession(&configAWS)), // DelayQueue: delayQueue, }) return &ServiceContext{ Config: c, MysqlConn: conn, AllModels: gmodel.NewAllModels(conn), Repositories: repositories, // DelayQueue: delayQueue, } }