Skip to content

Commit

Permalink
Merge pull request #13 from su-its/fix/backend/fixed-db-addr
Browse files Browse the repository at this point in the history
fix[typing-server]: 接続するDBのアドレスを環境変数で指定できるように
  • Loading branch information
h-takeyeah authored Mar 12, 2024
2 parents 981cce7 + e968f97 commit b60c7ed
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
11 changes: 8 additions & 3 deletions typing-server/api/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,20 @@ func main() {
return
}

var addr = os.Getenv("DB_ADDR")
if addr == "" {
addr = "db:3306" // アドレス(Docker Compose内でのサービス名とポート)
}

// MySQLの接続設定
mysqlConfig := &mysql.Config{
DBName: "typing-db", // データベース名
User: "user", // ユーザー名
Passwd: "password", // パスワード
Net: "tcp", // ネットワークタイプ
Addr: "db:3306", // アドレス(Docker Compose内でのサービス名とポート)
ParseTime: true, // 時刻をtime.Timeで解析する
Loc: jst, // タイムゾーン
Addr: addr,
ParseTime: true, // 時刻をtime.Timeで解析する
Loc: jst, // タイムゾーン
}

// entクライアントの初期化
Expand Down
2 changes: 2 additions & 0 deletions typing-server/docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ services:
dockerfile: Dockerfile
volumes:
- ./api:/app
environment:
DB_ADDR: ${DB_ADDR:-db:3306}
ports:
- "8080:8080"
networks:
Expand Down
2 changes: 2 additions & 0 deletions typing-server/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ services:
dockerfile: Dockerfile
volumes:
- ./api:/app
environment:
DB_ADDR: ${DB_ADDR:-db:3306}
ports:
- "8080:8080"
networks:
Expand Down

0 comments on commit b60c7ed

Please sign in to comment.