You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
753 B

package svc
import (
{{.configImport}}
"gorm.io/driver/mysql"
"gorm.io/gorm"
// xxx "{}/model/xxx" //原版注册方法
)
type ServiceContext struct {
Config {{.config}}
{{.middleware}}
GormDb *gorm.DB
// XxxModel xxx.xxxModel //
}
func NewServiceContext(c {{.config}}) *ServiceContext {
// Gorm ORM
dsn := c.MysqlConnStr
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
if err != nil {
panic(err)
}
// // XxxModel
//conn := sqlx.NewMysql(c.MysqlConnStr)
//if err != nil {
// panic(err)
//}
return &ServiceContext{
Config: c,
GormDb: db,
{{.middlewareAssignment}}
//XxxModel: xxx.NewXxxModel(conn, c.CacheRedis), //
}
}