33 lines
737 B
Go
33 lines
737 B
Go
|
|
package impl
|
||
|
|
|
||
|
|
import (
|
||
|
|
"fmt"
|
||
|
|
|
||
|
|
"git.apinb.com/bsm-sdk/core/cache/redis"
|
||
|
|
"git.apinb.com/bsm-sdk/core/logger"
|
||
|
|
"git.apinb.com/bsm-sdk/core/with"
|
||
|
|
"git.apinb.com/ops/logs/internal/config"
|
||
|
|
"git.apinb.com/ops/logs/internal/models"
|
||
|
|
"gorm.io/gorm"
|
||
|
|
)
|
||
|
|
|
||
|
|
var (
|
||
|
|
RedisService *redis.RedisClient
|
||
|
|
DBService *gorm.DB
|
||
|
|
)
|
||
|
|
|
||
|
|
func NewImpl() {
|
||
|
|
RedisService = with.RedisCache(config.Spec.Cache)
|
||
|
|
DBService = with.Databases(config.Spec.Databases, nil)
|
||
|
|
logger.New(nil)
|
||
|
|
|
||
|
|
if DBService != nil {
|
||
|
|
if err := DBService.AutoMigrate(models.GetAllModels()...); err != nil {
|
||
|
|
panic(fmt.Sprintf("logs migrate: %v", err))
|
||
|
|
}
|
||
|
|
if err := models.InitData(); err != nil {
|
||
|
|
panic(fmt.Sprintf("logs init data: %v", err))
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|