简体   繁体   中英

Build an app on Heroku using Go Module. change the root directory

I choose the way Go Module Specifics to build my Go app.

When I set the directory like below, it works well.

main.go
go.mod
go.sum
README.md

where go.mod

module xxx

// +heroku goVersion go1.18
go 1.18
...

But I want to put the all source code in the src folder. and push to Heroku, it will wrong

README.md
📂 src
  - main.go
  - go.mod
  - go.sum

Is there a way to do this?

Your go.mod (and go.sum ) files need to be in the codebase root directory . Buildpack will search the codebase for main package(s) and compile them all. You can override this behavior (what get's build) by using +heroku install build directive:

When using go modules, this buildpack will search the code base for main packages, ignoring any in vendor/, and will automatically compile those packages. If this isn't what you want you can specify specific package spec(s) via the go.mod file's // +heroku install directive (see below).

README.md
- go.mod
- go.sum
📂 src
  - main.go

I don't think you can use Go Module Specifics with go.mod file on deeper level than root in Heroku but your code can indeed be in subdirectory.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM