第 0 阶段:项目初始化

This commit is contained in:
yml
2026-05-22 15:05:28 +08:00
commit 8e7f1f17f0
55 changed files with 4519 additions and 0 deletions
+10
View File
@@ -0,0 +1,10 @@
package database
import (
"gorm.io/driver/mysql"
"gorm.io/gorm"
)
func OpenMySQL(dsn string) (*gorm.DB, error) {
return gorm.Open(mysql.Open(dsn), &gorm.Config{})
}
+25
View File
@@ -0,0 +1,25 @@
package database
import (
"context"
"github.com/redis/go-redis/v9"
)
type RedisConfig struct {
Addr string
Password string
DB int
}
func OpenRedis(ctx context.Context, cfg RedisConfig) (*redis.Client, error) {
client := redis.NewClient(&redis.Options{
Addr: cfg.Addr,
Password: cfg.Password,
DB: cfg.DB,
})
if err := client.Ping(ctx).Err(); err != nil {
return nil, err
}
return client, nil
}