fusenapi/home-user-auth/internal/svc/servicecontext.go
2023-05-31 18:33:02 +08:00

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,
}
}