fusenapi/server/order/internal/svc/servicecontext.go

45 lines
1.1 KiB
Go
Raw Normal View History

2023-09-20 07:07:12 +00:00
package svc
import (
"fusenapi/server/order/internal/config"
2023-09-28 09:53:41 +00:00
"fusenapi/utils/queue"
2023-09-20 07:07:12 +00:00
"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"
2023-09-20 07:07:12 +00:00
"gorm.io/gorm"
)
type ServiceContext struct {
Config config.Config
MysqlConn *gorm.DB
AllModels *gmodel.AllModelsGen
Repositories *initalize.Repositories
2023-09-28 09:53:41 +00:00
DelayQueue *queue.DelayMessage
2023-09-20 07:07:12 +00:00
}
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),
}
2023-09-20 07:07:12 +00:00
conn := initalize.InitMysql(c.SourceMysql)
2023-10-07 07:42:25 +00:00
// delayQueue := initalize.InitDelayMessage()
2023-09-28 09:53:41 +00:00
repositories := initalize.NewAllRepositories(&initalize.NewAllRepositorieData{
GormDB: conn,
AwsSession: session.Must(session.NewSession(&configAWS)),
2023-10-07 07:42:25 +00:00
// DelayQueue: delayQueue,
2023-09-28 09:53:41 +00:00
})
2023-09-20 07:07:12 +00:00
return &ServiceContext{
2023-09-28 09:53:41 +00:00
Config: c,
MysqlConn: conn,
AllModels: gmodel.NewAllModels(conn),
Repositories: repositories,
2023-10-07 07:42:25 +00:00
// DelayQueue: delayQueue,
2023-09-20 07:07:12 +00:00
}
}