I making game server in golang and i have such entities as Player
and Skill
. Player
can use his skills whilst Skill
could affect players. Player
file and skills files live in logic
directory(and in package logic
). I want to move skills files into separate directory skills
. I could not place it in logic directory and keep logic package for them cause golang not allowed it. Also i could not make package skills
and place the directory on same level as logic directory because i got:
import cycle not allowed
package main
imports projname/server/logic
imports projname/server/skills
imports projname/server/logic
What's wrong with my project architecture and how could i fix it?
your main
package imports
logic
package. It also imports skills
which also imports
logic
. Go is very strict about not allowing import cycles.
If you are forced to import
logic
in main
, because you are using some type declared in logic
to init a function or handler in skills
. You could, probably declare that type in skills
rather than in logic
.
If you are import
ing logic
because some function from logic is being used in main
. You could write a wrapper in skills
(with a new function), which calls the function from logic
(which is already being called).
Either way you have to try and remove the import of logic
in main
.