> Go언어로 짠 것 Heroku에 배포하기
Crescent
0. 서론
Getting Started on Heroku with Go - Heroku Dev Center
- 순서가 조금은 뒤죽박죽 일 수도 있습니다.
- 설명이 부족할 수 있습니다.
- 미래의 제가 이 글을 쓰는 저에게 감사를 표하기 위해 썼습니다.
01. Edit main.go
func main() {
gin.SetMode(gin.ReleaseMode)
router := gin.Default()
router.GET("/api/v1/:slug", getUser)
port := os.Getenv("PORT")
router.Run(":" + port)
}import "os"해두고os.Getenv()를 이용해 중요한 변수들을 관리한다.gin에서는 배포용일 때는gin.SetMode(gin.ReleasMode)를 써야 한다고 한다.- 포트 번호는 정해두면 배포에 문제가 생긴다고 한다.
go mod init crescent-stdio/todo-list
go tidy
go mod vendor- 기본 설정
02. git
git init
git branch -m main
git add .
git commit -m "Heroku deploy test"- 기본적인
git을 설정하고 커밋한다.
03. Heroku CLI
brew tap heroku/brew && brew install herokuMac기준으로Heroku를 설치- 다른 os는 다음 참고: Getting Started on Heroku with Go
heroku create crescent-todo
heroku git:remote -a crescent-todocrescent-todo는 이름 마음대로

GIN_MODE="release".env파일을 다음과 같이 넣어준다.(GIN_MODE가 있어야 한다고 에러메세지가 그러긴 했는데 확실히는 모르겠다)- 아까
main.go에는PORT가 있지만.env와Config Vars에 안넣어도 잘 작동한다.
web: bin/todoroot에Procfile을bin/뭐시기로 설정한다.
04. main.go build
go build -o bin/todo -v .Procfile에 설정한 이름 그대로 쓰면 된다..← 빼먹지 말기
05. Heroku Deploy
git push heroku main
heroku ps:scale web=1Configure Dynos가서ON시킨다.
git push heroku main- 푸싱!!
- 배포!!!
heroku open crescent-tododeploy한 사이트 오픈
heroku logs --tail- 실시간 로그는 다음으로 확인할 수 있다.
Crescent