package repo import ( "context" "chatapp3-golang/internal/config" "github.com/redis/go-redis/v9" "gorm.io/driver/mysql" "gorm.io/gorm" ) type Repository struct { DB *gorm.DB Redis *redis.Client } func New(cfg config.Config) (*Repository, error) { db, err := gorm.Open(mysql.Open(cfg.Store.MySQLDSN), &gorm.Config{}) if err != nil { return nil, err } client := redis.NewClient(&redis.Options{ Addr: cfg.Store.RedisAddr, Password: cfg.Store.RedisPassword, DB: cfg.Store.RedisDB, }) return &Repository{DB: db, Redis: client}, nil } func (r *Repository) Ping(ctx context.Context) error { if err := r.Redis.Ping(ctx).Err(); err != nil { return err } sqlDB, err := r.DB.DB() if err != nil { return err } return sqlDB.PingContext(ctx) }