Circular imports and GORM | 211230


Circular imports and GORM

GORM leads it self to putting you in a circular import loop by design and I have come to learn that from trying to add this temp user struct due to them being many to many

Had to go back and updo some things to get this back

So each server is going to have many users and have each user is going to have many servers (in theory)

Users Many2Many

But I did deem them close enough together in scope to be in the same package like channels and servers.

which leads to the user needing the server to define user and vise versa.

doom linking

Loop de loop and in go that is a no go.

So what do. There are few options

  • interface your way out of
    • Which doesn’t make to much since to me for some reason
  • Autonomous structure passing
    • Which mite work but not positive and seems kinda hacky
  • Mess with the project structure some more.
    • SO I am going to move all the things into there packages(channels, servers,messages, and users)
    • Does this fix the problem Nope, but I will also stop calling the object it self and just call ID of the associated item.( I already played with this in the Channel)

How did I not see this coming?

I did know about circular imports, but just didn’t think about it until I had had already done it. The GORM documentation did help, but its still on me but here: Do you see it

Okay here(above) do you see it? They are in the same file. I just filtered that out in my head.

Thought I just share that. I would like to move away from GORM at some point cause it’s not the fastest performance wise, but until I get closer to a finalized data model i am going to lean on it to save some time