./main.go:10: undefined: NewRouter
Closed this issue ยท 2 comments
Hi,
I am having issues when runngin go get on v9 of the project. I get the following error
./main.go:10: undefined: NewRouter
Can anyone explain what is wrong. I have checked my goroot, gobin and gopath variables and they all seem fine.
Thanks
Jonathan
Hi @KITSJonathanDixon, maybe you are trying to run the code using go run main.go
? If so, go run
is used to run only one file, otherwise you'll have to use go build
and run the executable generated by it.
One other option is to separate all files into folders and make the proper imports and then you'll be able to run the code with go run main.go
@KITSJonathanDixon @corylanou The original author needs to clarify this for new users.
But in order to run this example. Simple do:
go build
If you do
ls
You'll see a binary file. Just run it (it created api for me), so just run:
./api
and look at localhost:8080