My code is simple.
Project/
main.go
pokemons/
pokemon.go
pokeTrainers/
pokeTrainer.go
I have some Pokemon trainers which are defined like this :
package pokeTrainers
import "../pokemons"
type PokeTrainer struct {
name string
pokemon []Pokemon
}
And some Pokemon :
package pokemons
import "../pokeTrainers"
type Pokemon struct {
name string
pokeTrainers PokeTrainer
}
main package is:
package main
import (
"fmt"
"./pokemons"
"./pokeTrainers"
)
func main() {
fmt.Printf("ERROR CIRCULAR IMPORT")
As always when I have an error, I copy-paste it on google. I learn what's a circular import and how people fix it with interface to use methods from another package without import it. But in my case, the problem is not to use methods but a real Type defined in another package.
So you will probably say: "Man you are dumb ! You just have to put everything on the same package and it's fine !" Sorry, I come from Java and I would like that my code stays clean. ;)
I saw this link which suggest to use a third party packages ? But you have to imagine that I don't have only pokemon and pokeTrainer, I have many more packages with a type inside and a lot of methods..
What do you think ? How can I fix this error proprelly ? I'm a beginner in Go