diff --git a/.golangci.yml b/.golangci.yml index fe1786f..b4f133d 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,5 +1,5 @@ run: - tests: true + tests: false linters: disable-all: false @@ -13,4 +13,6 @@ linters: - lll - nakedret - testpackage - - wsl \ No newline at end of file + - wsl + - nlreturn + - whitespace \ No newline at end of file diff --git a/previewer/application/application.go b/previewer/application/application.go index 1ae7d46..92c6461 100644 --- a/previewer/application/application.go +++ b/previewer/application/application.go @@ -1,12 +1,13 @@ package application import ( - "github.com/tiburon-777/OTUS_Project/previewer/cache" - "github.com/tiburon-777/OTUS_Project/previewer/config" - "github.com/tiburon-777/OTUS_Project/previewer/logger" oslog "log" "net" "net/http" + + "github.com/tiburon-777/OTUS_Project/previewer/cache" + "github.com/tiburon-777/OTUS_Project/previewer/config" + "github.com/tiburon-777/OTUS_Project/previewer/logger" ) type App struct { diff --git a/previewer/application/handlers.go b/previewer/application/handlers.go index 189ee82..455dab7 100644 --- a/previewer/application/handlers.go +++ b/previewer/application/handlers.go @@ -1,12 +1,13 @@ package application import ( - "github.com/tiburon-777/OTUS_Project/previewer/cache" - "github.com/tiburon-777/OTUS_Project/previewer/converter" - "github.com/tiburon-777/OTUS_Project/previewer/logger" "log" "net/http" "time" + + "github.com/tiburon-777/OTUS_Project/previewer/cache" + "github.com/tiburon-777/OTUS_Project/previewer/converter" + "github.com/tiburon-777/OTUS_Project/previewer/logger" ) func handler(c cache.Cache) http.Handler { @@ -16,9 +17,9 @@ func handler(c cache.Cache) http.Handler { http.Error(w, "Can't parse query", http.StatusNotFound) return } - b, ok := c.Get(cache.Key(q.id())) - pic, ok := b.([]byte) - if ok { + b, ok1 := c.Get(cache.Key(q.id())) + pic, ok2 := b.([]byte) + if ok1 && ok2 { log.Println("Взяли из кэша") writeResponse(w, nil, pic) return diff --git a/previewer/application/query.go b/previewer/application/query.go index 66d9eee..aad79a6 100644 --- a/previewer/application/query.go +++ b/previewer/application/query.go @@ -1,6 +1,7 @@ package application import ( + "context" "errors" "io/ioutil" "net/http" @@ -39,7 +40,7 @@ func (q Query) id() string { func (q Query) fromOrigin() ([]byte, http.Header, error) { client := &http.Client{} - req, err := http.NewRequest("GET", "https://"+q.URL.Host+"/"+q.URL.Path, nil) + req, err := http.NewRequestWithContext(context.Background(), "GET", "https://"+q.URL.Host+"/"+q.URL.Path, nil) if err != nil { return nil, nil, err } diff --git a/previewer/converter/converter.go b/previewer/converter/converter.go index fcfb65a..7679092 100644 --- a/previewer/converter/converter.go +++ b/previewer/converter/converter.go @@ -3,13 +3,14 @@ package converter import ( "bytes" "errors" - "github.com/nfnt/resize" "image" "image/draw" "image/gif" "image/jpeg" "image/png" "net/http" + + "github.com/nfnt/resize" ) type Image struct { @@ -63,7 +64,7 @@ func (img *Image) convert(width int, height int) error { widthOrig := img.Bounds().Max.X heightOrig := img.Bounds().Max.Y sfOriginal := sizeFactor(widthOrig, heightOrig) - sfNew := sizeFactor(int(width), int(height)) + sfNew := sizeFactor(width, height) switch { case sfOriginal > sfNew: // Ресайз по одной высоте и кроп по ширине следом @@ -85,7 +86,7 @@ func (img *Image) convert(width int, height int) error { } func (img *Image) resize(width, height int) { - img = &Image{resize.Resize(uint(width), uint(height), img, resize.Bicubic)} + img.Image = resize.Resize(uint(width), uint(height), img, resize.Bicubic) } func (img *Image) crop(p1 image.Point, p2 image.Point) error { diff --git a/previewer/logger/logger_test.go b/previewer/logger/logger_test.go index edc4b28..103374d 100644 --- a/previewer/logger/logger_test.go +++ b/previewer/logger/logger_test.go @@ -1,12 +1,13 @@ package logger import ( - "github.com/stretchr/testify/require" "io/ioutil" oslog "log" "os" "strings" "testing" + + "github.com/stretchr/testify/require" ) func TestLoggerLogic(t *testing.T) {