Carson
Carson

Reputation: 7968

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?

Upvotes: 0

Views: 244

Answers (1)

blami
blami

Reputation: 7411

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.

Upvotes: 1

Related Questions