|
Kuule hain nussivan posted:Hello Go-thread. I'm planning my first Go-project with a couple of people and am having a hard time figuring out whether my design choices are sane or not, please help if you have the time. Cloud Run's free tier has been great for me. I did move a service to GKE that had some larger memory requirements, but Cloud Run seems to work for everything else. For loggers, I honestly use package level variables, as they tend to be safe for concurrent use, and don't impact my overall application design very much. For other things, like DB connections, or other service connections, I typically instantiate a Server struct, and provide those connections or configuration to it in the main function. This helps you structure your handlers in a way where it's easier to plug in a fake database for testing, or a fake/in-memory database or service for local development. I find it helps me keep a separation of concerns between different objects in my app. In general, instantiating things in Go is extremely cheap, so I take advantage of that unless I want persistent connections, which is frequently the case for databases and other services. If you're new to Go, one of the first things that helped me a lot when learning how to work with the language was that in general, functions should return pointers to structs, and accept interfaces as arguments. Interface definitions should go by where they're consumed, not where they're produced. This will help you keep a good contract at the call-site, and make it easier to change implementations without breaking consumers. As a bonus, it makes things really easy to fake out for unit testing, helping you avoid integration tests except where necessary. Finally, always run tests with the race detector on, and use go vet. Have fun.
|
# ¿ Sep 20, 2020 19:31 |
|
|
# ¿ May 11, 2024 08:00 |