31 lines
555 B
Go
31 lines
555 B
Go
// Code scaffolded by goctl. Safe to edit.
|
|
// goctl 1.10.1
|
|
|
|
package svc
|
|
|
|
import (
|
|
"sundynix-micro-go/app/system/api/internal/config"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
"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.DB.DataSource), &gorm.Config{})
|
|
if err != nil {
|
|
logx.Errorf("连接数据库失败: %v", err)
|
|
panic(err)
|
|
}
|
|
|
|
return &ServiceContext{
|
|
Config: c,
|
|
DB: db,
|
|
}
|
|
}
|