Skip to content

Commit

Permalink
Merge pull request #140 from Tibz-Dankan/refactor/dir-structure
Browse files Browse the repository at this point in the history
refactor: get the db url basing on the environment
  • Loading branch information
Tibz-Dankan authored Aug 24, 2024
2 parents 784f6ed + ebfae92 commit a39215a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ COPY . .

RUN go build -o ./bin/appcrons ./cmd

ENV GO_ENV=production

EXPOSE 8080

CMD ["./bin/appcrons"]
20 changes: 19 additions & 1 deletion internal/config/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,25 @@ import (
)

func Db() *gorm.DB {
dsn := os.Getenv("DSN_KEEP_ACTIVE")
var dsn string

env := os.Getenv("GO_ENV")
log.Println("GO_ENV:", env)

if env == "development" {
dsn = os.Getenv("APPCRONS_DEV_DSN")

} else if env == "testing" {
dsn = os.Getenv("APPCRONS_TEST_DSN")

} else if env == "staging" {
dsn = os.Getenv("APPCRONS_STAG_DSN")

} else if env == "production" {
dsn = os.Getenv("APPCRONS_PROD_DSN")
}

log.Println("dsn:", dsn)

db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{
SkipDefaultTransaction: true, PrepareStmt: true,
Expand Down

0 comments on commit a39215a

Please sign in to comment.