title: How to solve this Go cyclical dependency
body: <p>I've been learning Go for a class course and I am very excited with the language, it really is very useful for web services.</p>
  
  <p>So, I've been writing this CRUD restful API for a final project and I keep running in  the damn circular dependency problem. I've already researched and read on the ways of solving it and will post here just for the sake of it, but first the problem I am having:</p>
  
  <p><em>routes</em> need to know about the handler functions in the <em>handlers</em> package, which in turn need to know about the <em>user</em> structure inside the <em>model</em> package, which in order to send a registration e-mail with a link need to know about the <em>routes</em> path</p>
  
  <p>Classical A -> B -> C -> A</p>
  
  <p>Now, I am trying to write this API using MVC and three layer architecture, this I would love for my routes to be in a controller package, my handlers to be on a business logic package and my user on a model package. This is also needed because I have over 43 model classes, I need them tidy up and tucked away on their package.</p>
  
  <p>Ok, the solutions I found out</p>
  
  <p>1 - <strong>Throw everybody on the same package</strong> : That's what I've been doing so far but is a very horrible solution for obvious reasons.</p>
  
  <p>2- <strong>Pass whatever <em>user</em> needs as argument when it's functions are called</strong>: That would be a good solution, but won't work because the function that is being called from <em>user</em> is from an interface implementation because it has to be a generic call and before anyone goes around saying that my problem is because I am forcing generics in go, well too bad, I need that generic, I will not write over 160 crud functions. The whole point of functions is to avoid code repetition.</p>
  
  <p>3- <strong>Create another package, with another interface, and have it having a instance of handlers and user and have it pass arguments from one to the other</strong>: Despite the reason mentioned above, the need of generic, this sounds like an unnecessarily complicated solution, I refuse to believe that this is better design than circular dependencies.</p>
  
  <p>Bottom line question: How to solve this dependency when C needs to know information from A and generics must be respected</p>
  
  <p>I can post some code here if you need to but I don't see the relevance of specific code when this is more of a high level question.</p>
  
  <p><strong>EDIT</strong>: Solved my dependency problem. Thank you all for the comments and answer as it led me to the answer. I don't think I've implemented any of the solutions suggested but it did taught me a lot about how to solve the problem, and they would all be very acceptable and doable solution if it wasn't for my own constrains where I don't want to pass anything to User.
  To anyone trying to solve their own dependency problem, what I was able to gather is, instead of making in my case, C ask something from A, give to C whatever it needs, before it has to ask, meaning pass the information to him.</p>
  
  <p>Alas, that was not my solution, what I did was remove the information from A and give the information to Z, now both A and C are asking the path information to Z, which is just a Map, sitting there being all map like and holding information.
  Thank you all</p>