Skip to content

Commit

Permalink
Update MySQL TimeZone
Browse files Browse the repository at this point in the history
  • Loading branch information
mhmmdriz committed Jun 25, 2024
1 parent 2e0ea2f commit b7feb21
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ WORKDIR /app

COPY . .

RUN apk add --no-cache tzdata

RUN go mod download

RUN go build -o /goapp
Expand All @@ -12,6 +14,7 @@ FROM alpine:3.19 AS build-release-stage

WORKDIR /

COPY --from=build-stage /usr/share/zoneinfo /usr/share/zoneinfo
COPY --from=build-stage /goapp /goapp
COPY --from=build-stage /app/templates ./templates

Expand Down
10 changes: 9 additions & 1 deletion drivers/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"e-complaint-api/drivers/mysql/seeder"
"e-complaint-api/entities"
"fmt"
"time"

"gorm.io/driver/mysql"
"gorm.io/gorm"
Expand All @@ -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=Local",
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 {
Expand Down

0 comments on commit b7feb21

Please sign in to comment.