feat: 初次启动
This commit is contained in:
@@ -1,13 +1,44 @@
|
||||
package svc
|
||||
|
||||
import "sundynix-micro-go/app/radio/rpc/internal/config"
|
||||
import (
|
||||
radioModel "sundynix-micro-go/app/radio/model"
|
||||
"sundynix-micro-go/app/radio/rpc/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 {
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
db, err := gorm.Open(mysql.Open(c.DB.DataSource), &gorm.Config{})
|
||||
if err != nil {
|
||||
logx.Errorf("连接数据库失败: %v", err)
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if err := db.AutoMigrate(
|
||||
&radioModel.SundynixRadioUserProfile{},
|
||||
&radioModel.SundynixRadioCategory{},
|
||||
&radioModel.SundynixRadioChannel{},
|
||||
&radioModel.SundynixRadioProgram{},
|
||||
&radioModel.SundynixRadioVoice{},
|
||||
&radioModel.SundynixRadioLike{},
|
||||
&radioModel.SundynixRadioFavorite{},
|
||||
&radioModel.SundynixRadioComment{},
|
||||
&radioModel.SundynixRadioHistory{},
|
||||
&radioModel.SundynixRadioSubscription{},
|
||||
&radioModel.SundynixRadioSubscriptionOrder{},
|
||||
&radioModel.SundynixRadioPayNotify{},
|
||||
&radioModel.SundynixRadioVipConfig{},
|
||||
&radioModel.SundynixRadioListenLog{},
|
||||
); err != nil {
|
||||
logx.Errorf("数据库迁移失败: %v", err)
|
||||
}
|
||||
|
||||
return &ServiceContext{Config: c, DB: db}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user