diff --git a/drivers/mysql/mysql.go b/drivers/mysql/mysql.go index f5a8d48..af73423 100644 --- a/drivers/mysql/mysql.go +++ b/drivers/mysql/mysql.go @@ -5,6 +5,7 @@ import ( "e-complaint-api/drivers/mysql/seeder" "e-complaint-api/entities" "fmt" + "time" "gorm.io/driver/mysql" "gorm.io/gorm" @@ -19,12 +20,19 @@ type Config struct { } func ConnectDB(config Config) *gorm.DB { - dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=True&loc=Asia/Jakarta", + loc, err := time.LoadLocation("Asia/Jakarta") + if err != nil { + panic(err) + } + + // Creating the DSN with loc parameter + dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=True&loc=%s", config.DB_USERNAME, config.DB_PASSWORD, config.DB_HOST, config.DB_PORT, config.DB_NAME, + loc.String(), ) db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{}) if err != nil {