Ублажил линтер

master
Andrey Ivanov 2020-10-27 14:03:52 +03:00 committed by tiburon
parent ce36dd5a07
commit 534f58e49e
6 changed files with 23 additions and 16 deletions

View File

@ -1,5 +1,5 @@
run:
tests: true
tests: false
linters:
disable-all: false
@ -13,4 +13,6 @@ linters:
- lll
- nakedret
- testpackage
- wsl
- wsl
- nlreturn
- whitespace

View File

@ -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 {

View File

@ -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

View File

@ -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
}

View File

@ -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 {

View File

@ -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) {