first of all: I really really like golang. But the one thing that bothers me so much that I am almost at the point of rewriting my entire codebase of an almost finished REST api in nodejs is the file/directory structure and the layout of packages in golang. I googled alot and nobody seems to be having problems structuring their go project using the strict package system in go, so I think I am just too dumb to understand it correctly.
I am creating a REST Api using the gin framework and firestore. I have a database package which contains a DatabseService struct that has a firestore client. The databse package also contains about 50 methods (CreateUser, GetUserByUsername, CheckUsernameUniqueness… you get the idea) for the DatabaseService type. It looks like a mess in the directory of the database package and i am always spending 5 minutes to find the right file I want to change at the moment. So i want to split the files up into subdirectories, but then each subdirectory is its own package in golang and each package needs a DatabaseService type which contains the firestore client. In the main function i have to create x instances of the various DatabaseService types instead of one, which feels like a lot of code duplication. I just don’t understand how to structure my go code so i can group functions together and still using only one type and instance of DatabaseService.
I am a bit tired so I am sorry if its a bit confusing, but I just don’t know how to verbalize my problem properly. I hope somebody understands what i mean and can help me out/point in the right direction. If you need code sample to get what I mean let me know, then I will provide some.