25 lines
387 B
Go
25 lines
387 B
Go
package svc
|
|
|
|
import (
|
|
"home-user-auth/internal/config"
|
|
|
|
"gorm.io/driver/mysql"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type ServiceContext struct {
|
|
Config config.Config
|
|
DB *gorm.DB
|
|
}
|
|
|
|
func NewServiceContext(c config.Config) *ServiceContext {
|
|
db, err := gorm.Open(mysql.Open(c.DataSourceName), &gorm.Config{})
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return &ServiceContext{
|
|
Config: c,
|
|
DB: db,
|
|
}
|
|
}
|