Our great sponsors
-
WorkOS
The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.
-
embedded-postgres
Run a real Postgres database locally on Linux, OSX or Windows as part of another Go application or test
-
go-training
Go Training Repositories regroups some useful resources to learn Go Programming Language
When I started learning golang almost 9 years ago I've learned myself to structure it like a Laravel framework. The main api is also build in that fashion and to big to split it up or rebuild it.. Which bit me in the ass quite a few times. I recently switched job and am unlearning the MVC setup and trying to build it more like described here : https://github.com/golang-standards/project-layout
So what can you do insted? For testing databases, setup a docker instance for tests (e.g. like in https://github.com/ardanlabs/service), or start an embedded-postgres daemon (see https://github.com/fergusstrange/embedded-postgres). For communication with external APIs, just pass the http.Client (either in context.Context or as a field on the struct). Then in tests, you can override the http.Client.Transport func.
So what can you do insted? For testing databases, setup a docker instance for tests (e.g. like in https://github.com/ardanlabs/service), or start an embedded-postgres daemon (see https://github.com/fergusstrange/embedded-postgres). For communication with external APIs, just pass the http.Client (either in context.Context or as a field on the struct). Then in tests, you can override the http.Client.Transport func.
Related posts
- Read/Write FileSystem header interface for dependency injection
- Web request fuzzer with go
- Nunu: A CLI tool for building Go applications
- What's your go to literature to build Go libraries?
- I'm coming from Java and I have been told that I'm writing go like I'm writing Java. Basically creating structs, injecting fields, and attaching methods. What else can I do?