package svc import ( "gorm.io/driver/mysql" "gorm.io/gorm" "live-service/app/user_center/model" "live-service/app/user_center/rpc/internal/config" "log" ) type ServiceContext struct { Config config.Config UserModel model.UserModel UserPlatformModel model.UserPlatformModel } func NewServiceContext(c config.Config) *ServiceContext { gormDb, err := gorm.Open(mysql.Open(c.DB.DataSource), &gorm.Config{}) if err != nil { log.Fatal(err) } return &ServiceContext{ Config: c, UserModel: model.NewUserModel(gormDb), UserPlatformModel: model.NewUserPlatformModel(gormDb), } }