I make 3 go files with each of them is using the same package, which was package main. It will look like this...
mydir/
-client.go
-room.go
-main.go
In my terminal, there is no problem that appears on it, but when I try to run/build main.go, it's returning a panic:
undefined: newRoom
here was my snippet code which has panic :
//main.go
r := newRoom()
//room.go
func newRoom() *room{
return &room{}
}
When I try to delete the function, it's returning an error "Undeclared" in Visual Code. When adding it again, the problem disappears but when I try to run or build it, it returns an error if my newRoom function is undefined. Does anybody have a clue, what's wrong with it?
It's better if answered with some explanation why it doesn't appear on Visual Code Problems output.
Here is the command to build a binary from a directory with a bunch of files:
go build ./mydir/...
This command build the package in the mydir
folder and all packages recursing down. Run go help build
to get more about build
command.
There is no any issue with your code.