Skip to content

Commit

Permalink
refactor: rename
Browse files Browse the repository at this point in the history
  • Loading branch information
dongwlin committed Jan 12, 2025
1 parent 093f0a6 commit 309b03b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
4 changes: 3 additions & 1 deletion internal/db/db.go → internal/db/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 6 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"go.uber.org/zap"

_ "github.com/MirrorChyan/resource-backend/internal/banner"
_ "github.com/go-sql-driver/mysql"
)

var (
Expand All @@ -32,27 +31,27 @@ 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",
zap.Error(err),
)
}

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,
Expand Down

0 comments on commit 309b03b

Please sign in to comment.