Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

In Go, you can just use an interface which would make things mockable for testing.


But you still need to send around the object that implements the interface, right? That’s “DI”.


I don't think you need to do that.

Assuming a web application... You can instantiate the object in your main func and then attach it to the server struct so that it is available in every request. When mocking, you can create a mock server that instantiates mock items that implement the interface. If you need something that is contextual, you attach it to the context. In that case, you can still use mock objects, however, you would have to use a different middleware that handles the mock context objects instead of the normal middleware.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: