4

I got a Go API up on Heroku to which I push some code; in my procfile I have the following

web: main

In order to launch the Go built binary on Heroku's side. When I build it on my side with

go build cmd/main.go

It produces a binary file namned 'main' in my project root and works as expected but on Heroku I get

app[web.1]: bash: main: No such file or directory

The build process on Heroku seems fine, it finds all my dependencies and installs/compiles it all.

Entalpi
  • 2,005
  • 22
  • 33

2 Answers2

7

This was super simple once I realised this;

All main packages in the repo are compiled and binaries placed in the /app/bin directory, which is in the PATH. Binaries are named after the directory that contains them.

Entalpi
  • 2,005
  • 22
  • 33
  • yes, Heroku basically does "go install ./..." which does exactly that, make a binary named after the dir that contains go files with the package declared as main – David Budworth Jun 08 '16 at 14:31
  • I have the same error and can't make it work. I tried different names, but nothing happens, still `not found`... – franchb Nov 10 '17 at 20:26
  • Incase this might help others, it meant having a Procfile that looked like: "web: " – brianarpie Apr 01 '18 at 04:36
0

Another thing to note: Like other Go programs, the code in main.go has to belong to package main:

package main

func main() {
    // your code here
}

I'm afraid I totally forgot about this at first and it stumped me for a while.

blamblambunny
  • 757
  • 8
  • 19