I’m writing my first go web app and I have the following structure:
.
├── main.go
├── model
│ ├── model.go
│ └── book.go
├── route
│ └── route.go
└── view
└── view.go
/main.go is where my main() is located. In that file I also defined a variable Env where I’ll keep the instance of my database (at least that’s the plan).
In /main.go I do
import "project/view"
type Env struct {
db models.Collection
}
// rest of the code
func main() {
db, err := models.NewDB()
// etc
MyEnv := &Env{db}
// etc
}
But the thing is that in /view/view.go I need to call methods defined in /model/book.go and I thought the way to do that was through the MyEnv.db instance but of course I get an error:
view/view.go:13:14: undefined: Env
^^ Any help to solve that problem would be appreciated or any lead on how to better structure my project. :)