I have these two files:
daoFactory.go
package dao
import "sync"
type daoFactory struct {}
var instance *daoFactory
//some functions
fakeProvisionDao.go
package dao
import (
"sync"
"model"
)
type provisionDao struct {
}
var instance *provisionDao
//some functions
Both are in the same package: dao
.
I get this error:
"instance" redeclared in this block
Obviously, the cause is that instance
variable is declared in both files. I'm beggining in Go programming and I don't know how should I handle with this error.
Files have no real meaning for go, unlike in java, python and many others, they are just for you to organize your code as you see fit.
In go variables are visible package
wide, that means that both declartions of instance
are variables with package wide visibility. Hence the compiler complains about having two global variables with the same name.
Rename any one of your two instance variables and it will compile.
Reading the links in the comments above is highly recommend ;-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With