I am following this guide.
So at my current working directory I have five files. handles.go, logger.go, routes.go routes.go and main.go.
My main.go looks like the following:
package main
import (
"log"
"net/http"
)
func main() {
router := NewRouter()
log.Fatal(http.ListenAndServe(":8080", router))
}
NewRouter
is a function defined in routes.go
. Several other functions are also being called among those .go
. In the tutorial, I see no include/import statement for those .go
files; My guess is there must be some parameters that's being passed in go build
or go run
that will incorporate all the files? if so what is it?
评论:
sxan:
juniorsysadmin1:If all files are in the same directory, and they're all in package main, no imports are needed.
TheMerovius:it doesn't work when I do
go run main.go
it complain about the routerfunction that is defined inroutes.go
.
bishopknight1977:Use
go build
orgo run *.go
. run and build have very different behaviors, run is for running a set of go-files, whereas build is for building a package.
thornag:If you're using Gogland for IntelliJ you need to specify the run configuration to package . I had the same problem until I changed it.
You need to include all the files when running or building
go run ./... or go run *.go
