Monday, 9 November 2020

go web app 19 deploy to heroku


find GOPATH 
>go env GOPATH
C:\Users\bob\go

copy project directory to GOPATH/src
reinstall dependencies - go get ...

create go.mod
>go mod init example.com/election
go: creating new go.mod: module example.com/election

create go.sum
>go test
go: finding module for package github.com/gorilla/mux
go: finding module for package golang.org/x/crypto/bcrypt
...

create vendor folder
>govendor init

populate vendor folder
>go mod vendor

change port on main.go 
port := os.Getenv("PORT")
http.ListenAndServe(":"+port, nil)

create Procfile in project root directory (GOPATH/src)
web: bin/projectName

create new app on heroku
>git init
>heroku git:remote -a chuanshuoge-election
>git add .
>git commit -am "make it better"
>git push heroku master
remote:        https://chuanshuoge-election.herokuapp.com/ deployed to Heroku

free heroku dyno
>heroku ps:scale web=1

open app on heroku
go app is deployed on heroku
reference:

No comments:

Post a Comment