Deploy go app

There is a good example how to deploy GitHub - fly-apps/go-example: A minimal Go application for tutorials go app.
But in real life folder structure can be a little different.
In my case i have:

app1
main.go
app2
main.go
go.mod
go.sum

If i try to “flyctl launch” in app1 or app2 folder it looks like fly can’t find go app because no go.mod
So, the question is how to launch app1 and app2?

I found the solution:
[ build ]
[[ build.env ]]
name=“BP_GO_TARGETS”
value=“./app1”

but it doesn’t work. I got this error:
ERROR: No buildpack groups passed detection.
ERROR: Please check that you are running against the correct path.
ERROR: failed to detect: no buildpacks participating
Error failed to fetch an image or build from source: executing lifecycle: failed with status code: 20

I’m having the same problem. If anyone knows the solution, please do share.

I just moved my main.go to the root directory, and it now works fine.

Another option is creating a new main.go in the root directory, which just calls the main function from your other folder. e.g.

package main

import "myapp/app1"

func main() {
  app1.main()
}
1 Like