[Solved] route method becomes undefined in main package file


There are two problems:

#1

You need to have both files in the same directory with the same package name; namely, main.

#2

You need to compile and execute all files in this directory which you can do either using:

  • go run ./... to execute all files in this directory, or,

  • go run app.go main.go to execute just these two files.


Alternatively, as suggested by @mkopriva, you can move and export all handler functions to a different package, let’s call it package handlers and just import this package in your main app.

solved route method becomes undefined in main package file