Daily Archives: 26.02.2020
Clean architecture pattern
The main idea is to have layers that only depend on inner layers (see images below). Let’s imagine you have a repository that includes several applications. Layers Domain (Entities) Has basic types and interfaces for your application. As well as common logic for your domain. Usecase Services, handlers, controllers, whatever we call them. Adapters Implementations …
A way to test http client in go
A couple of ways are described here — http://hassansin.github.io/Unit-Testing-http-client-in-Go The way I liked is the following one:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
func Test_Mine(t *testing.T) { ... client := httpClientWithRoundTripper(http.StatusOK, "OK") ... } type roundTripFunc func(req *http.Request) *http.Response func (f roundTripFunc) RoundTrip(req *http.Request) (*http.Response, error) { return f(req), nil } func httpClientWithRoundTripper(statusCode int, response string) *http.Client { return &http.Client{ Transport: roundTripFunc(func(req *http.Request) *http.Response { return &http.Response{ StatusCode: statusCode, Body: ioutil.NopCloser(bytes.NewBufferString(response)), } }), } } |