From 309b03bf5f4d8c321247ca567cbbbd8efb640bd8 Mon Sep 17 00:00:00 2001 From: dongwlin Date: Sun, 12 Jan 2025 23:43:01 +0800 Subject: [PATCH] refactor: rename --- internal/db/{db.go => mysql.go} | 4 +++- main.go | 13 ++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) rename internal/db/{db.go => mysql.go} (79%) diff --git a/internal/db/db.go b/internal/db/mysql.go similarity index 79% rename from internal/db/db.go rename to internal/db/mysql.go index 0c5714f..1bb5b9d 100644 --- a/internal/db/db.go +++ b/internal/db/mysql.go @@ -5,9 +5,11 @@ import ( "github.com/MirrorChyan/resource-backend/internal/config" "github.com/MirrorChyan/resource-backend/internal/ent" + + _ "github.com/go-sql-driver/mysql" ) -func New(conf *config.Config) (*ent.Client, error) { +func NewMySQL(conf *config.Config) (*ent.Client, error) { dsn := fmt.Sprintf( "%s:%s@tcp(%s:%s)/%s?parseTime=True", conf.Database.Username, diff --git a/main.go b/main.go index 1455f65..5c12a41 100644 --- a/main.go +++ b/main.go @@ -14,7 +14,6 @@ import ( "go.uber.org/zap" _ "github.com/MirrorChyan/resource-backend/internal/banner" - _ "github.com/go-sql-driver/mysql" ) var ( @@ -32,7 +31,7 @@ func main() { db.NewRedis(conf) - database, err := db.New(conf) + mySQL, err := db.NewMySQL(conf) if err != nil { l.Fatal("failed to connect to database", @@ -40,19 +39,19 @@ func main() { ) } - defer func(database *ent.Client) { - err := database.Close() + defer func(mySQL *ent.Client) { + err := mySQL.Close() if err != nil { l.Fatal("failed to close database") } - }(database) + }(mySQL) - if err := database.Schema.Create(CTX); err != nil { + if err := mySQL.Schema.Create(CTX); err != nil { l.Fatal("failed creating schema resources", zap.Error(err)) } - handlerSet := wire.NewHandlerSet(conf, l, database) + handlerSet := wire.NewHandlerSet(conf, l, mySQL) app := fiber.New(fiber.Config{ BodyLimit: BodyLimit,