【Go】Goで作ったアプリをHerokuにデプロイするときにハマった
Goのginを使ってtodoアプリにログイン機能とログインセッション、パスワードをハッシュ化して保存など、機能を拡張したものを作りました。
デプロイしてみるか、ということでherokuにデプロイしてみようと思ったのですが、そこで何か所かハマりました。
sudo付け忘れ
Windows環境で、開発はwsl2で行っていました。Linuxなので当然ですが、sudoをつけないとエラーになるコマンドがあります。
バージョン
herokuにpushしていると、
vendor/gorm.io/gorm/utils/utils.go:46:30: reflect.ValueOf(val).IsZero undefined (type reflect.Value has no field or method IsZero)
が出ました。バージョンが足りてなさそうです。開発は1.13で行っており、go.modにもgo 1.13とありましたが、
remote: !! The go.mod file for this project does not specify a Go version remote: !! remote: !! Defaulting to go1.12.17 remote: !! remote: !! For more details see: https://devcenter.heroku.com/articles/go-apps-with-modules#build-configuration remote: !!
とあり、1.12.17で動作しているようです。調べた結果、go.modの内容を以下のように変更しました。
// +heroku goVersion go1.13 <----これを足す go 1.13
これで1.13で動作するようになり、エラーが消えました。
警告
remote: ! ## Warning - The same version of this code has already been built: bbad49b00710bedfaf2440742a213671e7f4f418 remote: ! remote: ! We have detected that you have triggered a build from source code with version bbad49b00710bedfaf2440742a213671e7f4f418 remote: ! at least twice. One common cause of this behavior is attempting to deploy code from a different branch. remote: ! remote: ! If you are developing on a branch and deploying via git you must run: remote: ! remote: ! git push heroku <branchname>:main
すでにそのコミットでのデプロイは試みてるよ、という確認メッセージでした。