...в угоду линтеру
parent
0f60b7a79f
commit
70ea092b98
|
@ -11,8 +11,10 @@ import (
|
|||
"github.com/tiburon-777/OTUS_Project/internal/config"
|
||||
)
|
||||
|
||||
var ConfigFile = flag.String("config", "/etc/previewer.conf", "Path to configuration file")
|
||||
var CleanCache = flag.Bool("clean", false, "Set true if you need clean cache before start app")
|
||||
var (
|
||||
ConfigFile = flag.String("config", "/etc/previewer.conf", "Path to configuration file")
|
||||
CleanCache = flag.Bool("clean", false, "Set true if you need clean cache before start app")
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
@ -33,7 +35,7 @@ func main() {
|
|||
}
|
||||
go func() {
|
||||
signals := make(chan os.Signal, 1)
|
||||
signal.Notify(signals, syscall.SIGINT, syscall.SIGKILL, syscall.SIGTERM)
|
||||
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM)
|
||||
|
||||
<-signals
|
||||
signal.Stop(signals)
|
||||
|
|
|
@ -28,7 +28,7 @@ func TestIntegrationPositive(t *testing.T) {
|
|||
go func(ctx context.Context) {
|
||||
main()
|
||||
}(ctx)
|
||||
time.Sleep(3*time.Second)
|
||||
time.Sleep(3 * time.Second)
|
||||
|
||||
// Реализовать тесты логики приложения (ресайзы по разным требованиям):
|
||||
wg.Add(18)
|
||||
|
@ -44,145 +44,145 @@ func TestIntegrationPositive(t *testing.T) {
|
|||
body, resp, err := request("http://localhost:8080/fill/1024/504/localhost:"+testPort+"/gopher_original_1024x504.jpg", 15*time.Second)
|
||||
require.NoError(t, err)
|
||||
fSize := 63488
|
||||
require.InDelta(t, len(body),fSize, float64(fSize/100)*2, "File size should be about "+strconv.Itoa(fSize/1024)+"Kb~2%")
|
||||
require.InDelta(t, len(body), fSize, float64(fSize/100)*2, "File size should be about "+strconv.Itoa(fSize/1024)+"Kb~2%")
|
||||
require.Equal(t, 200, resp.StatusCode)
|
||||
require.Equal(t,resp.Header.Get("X-From-Appcache"), "")
|
||||
require.Equal(t, resp.Header.Get("X-From-Appcache"), "")
|
||||
})
|
||||
t.Run("remote server return png in original size", func(t *testing.T) {
|
||||
defer wg.Done()
|
||||
body, resp, err := request("http://localhost:8080/fill/972/603/localhost:"+testPort+"/test.png", 15*time.Second)
|
||||
require.NoError(t, err)
|
||||
fSize := 433896
|
||||
require.InDelta(t, len(body),fSize, float64(fSize/100)*2, "File size should be about "+strconv.Itoa(fSize/1024)+"Kb~2%")
|
||||
require.InDelta(t, len(body), fSize, float64(fSize/100)*2, "File size should be about "+strconv.Itoa(fSize/1024)+"Kb~2%")
|
||||
require.Equal(t, 200, resp.StatusCode)
|
||||
require.Equal(t,resp.Header.Get("X-From-Appcache"), "")
|
||||
require.Equal(t, resp.Header.Get("X-From-Appcache"), "")
|
||||
})
|
||||
t.Run("remote server return gif in original size", func(t *testing.T) {
|
||||
defer wg.Done()
|
||||
body, resp, err := request("http://localhost:8080/fill/480/320/localhost:"+testPort+"/test.gif", 15*time.Second)
|
||||
require.NoError(t, err)
|
||||
fSize := 34508
|
||||
require.InDelta(t, len(body),fSize, float64(fSize/100)*2, "File size should be about "+strconv.Itoa(fSize/1024)+"Kb~2%")
|
||||
require.InDelta(t, len(body), fSize, float64(fSize/100)*2, "File size should be about "+strconv.Itoa(fSize/1024)+"Kb~2%")
|
||||
require.Equal(t, 200, resp.StatusCode)
|
||||
require.Equal(t,resp.Header.Get("X-From-Appcache"), "")
|
||||
require.Equal(t, resp.Header.Get("X-From-Appcache"), "")
|
||||
})
|
||||
t.Run("found pic in cache", func(t *testing.T) {
|
||||
defer wg.Done()
|
||||
body, resp, err := request("http://localhost:8080/fill/1024/504/localhost:"+testPort+"/gopher_original_1024x504.jpg", 15*time.Second)
|
||||
require.NoError(t, err)
|
||||
fSize := 63488
|
||||
require.InDelta(t, len(body),fSize, float64(fSize/100)*2, "File size should be about "+strconv.Itoa(fSize/1024)+"Kb~2%")
|
||||
require.InDelta(t, len(body), fSize, float64(fSize/100)*2, "File size should be about "+strconv.Itoa(fSize/1024)+"Kb~2%")
|
||||
require.Equal(t, 200, resp.StatusCode)
|
||||
require.Equal(t,resp.Header.Get("X-From-Appcache"), "true")
|
||||
require.Equal(t, resp.Header.Get("X-From-Appcache"), "true")
|
||||
})
|
||||
t.Run("resize PNG to 400x400", func(t *testing.T) {
|
||||
defer wg.Done()
|
||||
body, resp, err := request("http://localhost:8080/fill/400/400/localhost:"+testPort+"/test.png", 15*time.Second)
|
||||
require.NoError(t, err)
|
||||
fSize := 161317
|
||||
require.InDelta(t, len(body),fSize, float64(fSize/100)*2, "File size should be about "+strconv.Itoa(fSize/1024)+"Kb~2%")
|
||||
require.InDelta(t, len(body), fSize, float64(fSize/100)*2, "File size should be about "+strconv.Itoa(fSize/1024)+"Kb~2%")
|
||||
require.Equal(t, 200, resp.StatusCode)
|
||||
require.Equal(t,resp.Header.Get("X-From-Appcache"), "")
|
||||
require.Equal(t, resp.Header.Get("X-From-Appcache"), "")
|
||||
})
|
||||
t.Run("resize GIF to 200x200", func(t *testing.T) {
|
||||
defer wg.Done()
|
||||
body, resp, err := request("http://localhost:8080/fill/200/200/localhost:"+testPort+"/test.gif", 15*time.Second)
|
||||
require.NoError(t, err)
|
||||
fSize := 11913
|
||||
require.InDelta(t, len(body),fSize, float64(fSize/100)*2, "File size should be about "+strconv.Itoa(fSize/1024)+"Kb~2%")
|
||||
require.InDelta(t, len(body), fSize, float64(fSize/100)*2, "File size should be about "+strconv.Itoa(fSize/1024)+"Kb~2%")
|
||||
require.Equal(t, 200, resp.StatusCode)
|
||||
require.Equal(t,resp.Header.Get("X-From-Appcache"), "")
|
||||
require.Equal(t, resp.Header.Get("X-From-Appcache"), "")
|
||||
})
|
||||
t.Run("resize JPEG to 50x50", func(t *testing.T) {
|
||||
defer wg.Done()
|
||||
body, resp, err := request("http://localhost:8080/fill/50/50/localhost:"+testPort+"/gopher_original_1024x504.jpg", 15*time.Second)
|
||||
require.NoError(t, err)
|
||||
fSize := 1437
|
||||
require.InDelta(t, len(body),fSize, float64(fSize/100)*2, "File size should be about "+strconv.Itoa(fSize/1024)+"Kb~2%")
|
||||
require.InDelta(t, len(body), fSize, float64(fSize/100)*2, "File size should be about "+strconv.Itoa(fSize/1024)+"Kb~2%")
|
||||
require.Equal(t, 200, resp.StatusCode)
|
||||
require.Equal(t,resp.Header.Get("X-From-Appcache"), "")
|
||||
require.Equal(t, resp.Header.Get("X-From-Appcache"), "")
|
||||
})
|
||||
t.Run("resize JPEG to 200x70", func(t *testing.T) {
|
||||
defer wg.Done()
|
||||
body, resp, err := request("http://localhost:8080/fill/200/70/localhost:"+testPort+"/gopher_original_1024x504.jpg", 15*time.Second)
|
||||
require.NoError(t, err)
|
||||
fSize := 3875
|
||||
require.InDelta(t, len(body),fSize, float64(fSize/100)*2, "File size should be about "+strconv.Itoa(fSize/1024)+"Kb~2%")
|
||||
require.InDelta(t, len(body), fSize, float64(fSize/100)*2, "File size should be about "+strconv.Itoa(fSize/1024)+"Kb~2%")
|
||||
require.Equal(t, 200, resp.StatusCode)
|
||||
require.Equal(t,resp.Header.Get("X-From-Appcache"), "")
|
||||
require.Equal(t, resp.Header.Get("X-From-Appcache"), "")
|
||||
})
|
||||
t.Run("resize JPEG to 256x126", func(t *testing.T) {
|
||||
defer wg.Done()
|
||||
body, resp, err := request("http://localhost:8080/fill/256/126/localhost:"+testPort+"/gopher_original_1024x504.jpg", 15*time.Second)
|
||||
require.NoError(t, err)
|
||||
fSize := 6803
|
||||
require.InDelta(t, len(body),fSize, float64(fSize/100)*2, "File size should be about "+strconv.Itoa(fSize/1024)+"Kb~2%")
|
||||
require.InDelta(t, len(body), fSize, float64(fSize/100)*2, "File size should be about "+strconv.Itoa(fSize/1024)+"Kb~2%")
|
||||
require.Equal(t, 200, resp.StatusCode)
|
||||
require.Equal(t,resp.Header.Get("X-From-Appcache"), "")
|
||||
require.Equal(t, resp.Header.Get("X-From-Appcache"), "")
|
||||
})
|
||||
t.Run("resize JPEG to 333x666", func(t *testing.T) {
|
||||
defer wg.Done()
|
||||
body, resp, err := request("http://localhost:8080/fill/333/666/localhost:"+testPort+"/gopher_original_1024x504.jpg", 15*time.Second)
|
||||
require.NoError(t, err)
|
||||
fSize := 28749
|
||||
require.InDelta(t, len(body),fSize, float64(fSize/100)*2, "File size should be about "+strconv.Itoa(fSize/1024)+"Kb~2%")
|
||||
require.InDelta(t, len(body), fSize, float64(fSize/100)*2, "File size should be about "+strconv.Itoa(fSize/1024)+"Kb~2%")
|
||||
require.Equal(t, 200, resp.StatusCode)
|
||||
require.Equal(t,resp.Header.Get("X-From-Appcache"), "")
|
||||
require.Equal(t, resp.Header.Get("X-From-Appcache"), "")
|
||||
})
|
||||
t.Run("resize JPEG to 500x500", func(t *testing.T) {
|
||||
defer wg.Done()
|
||||
body, resp, err := request("http://localhost:8080/fill/500/500/localhost:"+testPort+"/gopher_original_1024x504.jpg", 15*time.Second)
|
||||
require.NoError(t, err)
|
||||
fSize := 32606
|
||||
require.InDelta(t, len(body),fSize, float64(fSize/100)*2, "File size should be about "+strconv.Itoa(fSize/1024)+"Kb~2%")
|
||||
require.InDelta(t, len(body), fSize, float64(fSize/100)*2, "File size should be about "+strconv.Itoa(fSize/1024)+"Kb~2%")
|
||||
require.Equal(t, 200, resp.StatusCode)
|
||||
require.Equal(t,resp.Header.Get("X-From-Appcache"), "")
|
||||
require.Equal(t, resp.Header.Get("X-From-Appcache"), "")
|
||||
})
|
||||
t.Run("resize JPEG to 1024x252", func(t *testing.T) {
|
||||
defer wg.Done()
|
||||
body, resp, err := request("http://localhost:8080/fill/1024/252/localhost:"+testPort+"/gopher_original_1024x504.jpg", 15*time.Second)
|
||||
require.NoError(t, err)
|
||||
fSize := 30356
|
||||
require.InDelta(t, len(body),fSize, float64(fSize/100)*2, "File size should be about "+strconv.Itoa(fSize/1024)+"Kb~2%")
|
||||
require.InDelta(t, len(body), fSize, float64(fSize/100)*2, "File size should be about "+strconv.Itoa(fSize/1024)+"Kb~2%")
|
||||
require.Equal(t, 200, resp.StatusCode)
|
||||
require.Equal(t,resp.Header.Get("X-From-Appcache"), "")
|
||||
require.Equal(t, resp.Header.Get("X-From-Appcache"), "")
|
||||
})
|
||||
t.Run("resize JPEG to 2000x1000", func(t *testing.T) {
|
||||
defer wg.Done()
|
||||
body, resp, err := request("http://localhost:8080/fill/2000/1000/localhost:"+testPort+"/gopher_original_1024x504.jpg", 15*time.Second)
|
||||
require.NoError(t, err)
|
||||
fSize := 151996
|
||||
require.InDelta(t, len(body),fSize, float64(fSize/100)*2, "File size should be about "+strconv.Itoa(fSize/1024)+"Kb~2%")
|
||||
require.InDelta(t, len(body), fSize, float64(fSize/100)*2, "File size should be about "+strconv.Itoa(fSize/1024)+"Kb~2%")
|
||||
require.Equal(t, 200, resp.StatusCode)
|
||||
require.Equal(t,resp.Header.Get("X-From-Appcache"), "")
|
||||
require.Equal(t, resp.Header.Get("X-From-Appcache"), "")
|
||||
})
|
||||
t.Run("remote server not exist (502 Bad request)", func(t *testing.T) {
|
||||
defer wg.Done()
|
||||
_, resp, err := request("http://localhost:8080/fill/1024/252/abracadabra/fakepic.jpg", 15*time.Second)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 502, resp.StatusCode)
|
||||
require.Equal(t,resp.Header.Get("X-From-Appcache"), "")
|
||||
require.Equal(t, resp.Header.Get("X-From-Appcache"), "")
|
||||
})
|
||||
t.Run("remote server exists, but pic not found (404 Not Found)", func(t *testing.T) {
|
||||
defer wg.Done()
|
||||
_, resp, err := request("http://localhost:8080/fill/1024/252/localhost:"+testPort+"/fakepic.jpg", 15*time.Second)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 404, resp.StatusCode)
|
||||
require.Equal(t,resp.Header.Get("X-From-Appcache"), "")
|
||||
require.Equal(t, resp.Header.Get("X-From-Appcache"), "")
|
||||
})
|
||||
t.Run("remote server exists, but pic is not pic (500 Internal Server Error)", func(t *testing.T) {
|
||||
defer wg.Done()
|
||||
_, resp, err := request("http://localhost:8080/fill/1024/252/localhost:"+testPort+"/test.exe", 15*time.Second)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 500, resp.StatusCode)
|
||||
require.Equal(t,resp.Header.Get("X-From-Appcache"), "")
|
||||
require.Equal(t, resp.Header.Get("X-From-Appcache"), "")
|
||||
})
|
||||
t.Run("remote server return plain html or texst", func(t *testing.T) {
|
||||
defer wg.Done()
|
||||
_, resp, err := request("http://localhost:8080/fill/1024/252/localhost:"+testPort+"/test.html", 15*time.Second)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 500, resp.StatusCode)
|
||||
require.Equal(t,resp.Header.Get("X-From-Appcache"), "")
|
||||
require.Equal(t, resp.Header.Get("X-From-Appcache"), "")
|
||||
})
|
||||
|
||||
// Закрыть сервер и приложение
|
||||
|
|
1
go.mod
1
go.mod
|
@ -10,4 +10,5 @@ require (
|
|||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/stretchr/testify v1.6.1
|
||||
gopkg.in/yaml.v2 v2.3.0 // indirect
|
||||
mvdan.cc/gofumpt v0.0.0-20201107090320-a024667a00f1 // indirect
|
||||
)
|
||||
|
|
31
go.sum
31
go.sum
|
@ -13,10 +13,15 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
|
|||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/google/go-cmp v0.5.1 h1:JFrFEBb2xKufg6XkJsJr+WbKb4FQlURi5RUcBveYu9k=
|
||||
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
||||
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
|
||||
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||
|
@ -27,6 +32,7 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
|||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
|
||||
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
|
||||
github.com/sirupsen/logrus v1.3.0 h1:hI/7Q+DtNZ2kINb6qt/lS+IyXnHQe9e90POfeewL/ME=
|
||||
github.com/sirupsen/logrus v1.3.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
||||
|
@ -43,6 +49,7 @@ github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd
|
|||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
|
||||
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
|
||||
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
go.uber.org/atomic v1.3.2 h1:2Oa65PReHzfn29GpvgsYwloV9AVFHPDk8tYxt2c2tr4=
|
||||
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
|
||||
go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI=
|
||||
|
@ -53,14 +60,36 @@ golang.org/x/crypto v0.0.0-20180904163835-0709b304e793 h1:u+LnwYTOOW7Ukr/fppxEb1
|
|||
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9 h1:mKdxBk7AujPs8kU4m80U72y/zjbZ3UcXC7dClwKbUI0=
|
||||
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/image v0.0.0-20190703141733-d6a02ce849c9/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||
golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
|
||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33 h1:I6FyU15t786LL7oL/hn43zqTuEGr4PN7F4XJ1p4E3Y8=
|
||||
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a h1:1n5lsVfiQW3yfsRGu98756EH1YthsFqr/5mxHduZW2A=
|
||||
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20200731060945-b5fad4ed8dd6 h1:qKpj8TpV+LEhel7H/fR788J+KvhWZ3o3V6N2fU/iuLU=
|
||||
golang.org/x/tools v0.0.0-20200731060945-b5fad4ed8dd6/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8=
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
|
@ -68,3 +97,5 @@ gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
|
|||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
mvdan.cc/gofumpt v0.0.0-20201107090320-a024667a00f1 h1:KYPCZAkhZoBOktjyX+LOwepZ+QYiOhb/KHmzkn0nCcs=
|
||||
mvdan.cc/gofumpt v0.0.0-20201107090320-a024667a00f1/go.mod h1:bzrjFmaD6+xqohD3KYP0H2FEuxknnBmyyOxdhLdaIws=
|
||||
|
|
|
@ -2,11 +2,12 @@ package application
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
|
||||
"github.com/tiburon-777/OTUS_Project/internal/cache"
|
||||
"github.com/tiburon-777/OTUS_Project/internal/config"
|
||||
"github.com/tiburon-777/OTUS_Project/internal/logger"
|
||||
"net"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
|
|
|
@ -80,4 +80,4 @@ func loggingMiddleware(next http.Handler, l logger.Interface) http.HandlerFunc {
|
|||
}()
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ func (l *lruCache) Set(key Key, value interface{}) (bool, error) {
|
|||
if l.queue.Len() == l.capacity {
|
||||
k, ok := l.queue.Back().Value.(Item)
|
||||
if !ok {
|
||||
return false, fmt.Errorf("can't cast type\n")
|
||||
return false, fmt.Errorf("can't cast type")
|
||||
}
|
||||
err := l.remove(k.Value.(Key))
|
||||
if err != nil {
|
||||
|
@ -90,7 +90,7 @@ func (l *lruCache) Get(key Key) (interface{}, bool, error) {
|
|||
l.queue.MoveToFront(l.items[key])
|
||||
s, ok := l.items[key].Value.(Item)
|
||||
if !ok {
|
||||
return nil, false, fmt.Errorf("can't cast type\n")
|
||||
return nil, false, fmt.Errorf("can't cast type")
|
||||
}
|
||||
pic, err := l.loadIn(s.Key)
|
||||
if err != nil {
|
||||
|
|
|
@ -16,7 +16,7 @@ func TestCache(t *testing.T) {
|
|||
cacheDir, err := ioutil.TempDir("", "cache_.")
|
||||
require.NoError(t, err, err)
|
||||
defer os.RemoveAll(cacheDir)
|
||||
c,err := NewCache(10, cacheDir)
|
||||
c, err := NewCache(10, cacheDir)
|
||||
require.NoError(t, err, err)
|
||||
err = c.Clear()
|
||||
require.NoError(t, err, err)
|
||||
|
@ -82,7 +82,7 @@ func TestCache(t *testing.T) {
|
|||
cacheDir, err := ioutil.TempDir("", "cache_.")
|
||||
require.NoError(t, err, err)
|
||||
defer os.RemoveAll(cacheDir)
|
||||
c,err := NewCache(3, cacheDir)
|
||||
c, err := NewCache(3, cacheDir)
|
||||
require.NoError(t, err, err)
|
||||
err = c.Clear()
|
||||
require.NoError(t, err, err)
|
||||
|
@ -128,7 +128,7 @@ func TestCacheMultithreading(t *testing.T) {
|
|||
cacheDir, err := ioutil.TempDir("", "cache_.")
|
||||
require.NoError(t, err, err)
|
||||
defer os.RemoveAll(cacheDir)
|
||||
c,err := NewCache(10, cacheDir)
|
||||
c, err := NewCache(10, cacheDir)
|
||||
require.NoError(t, err, err)
|
||||
err = c.Clear()
|
||||
require.NoError(t, err, err)
|
||||
|
@ -140,8 +140,8 @@ func TestCacheMultithreading(t *testing.T) {
|
|||
defer wg.Done()
|
||||
for i := 0; i < 10_000; i++ {
|
||||
itm := strconv.Itoa(i)
|
||||
_,err := c.Set(Key(itm), []byte(itm))
|
||||
require.NoError(t,err,err)
|
||||
_, err := c.Set(Key(itm), []byte(itm))
|
||||
require.NoError(t, err, err)
|
||||
}
|
||||
}()
|
||||
|
||||
|
@ -149,9 +149,11 @@ func TestCacheMultithreading(t *testing.T) {
|
|||
defer wg.Done()
|
||||
for i := 0; i < 10_000; i++ {
|
||||
itm := strconv.Itoa(rand.Intn(10_000))
|
||||
b,s,err := c.Get(Key(itm))
|
||||
require.NoError(t,err,err)
|
||||
if s {require.Equal(t, itm, string(b.([]uint8)))}
|
||||
b, s, err := c.Get(Key(itm))
|
||||
require.NoError(t, err, err)
|
||||
if s {
|
||||
require.Equal(t, itm, string(b.([]uint8)))
|
||||
}
|
||||
|
||||
}
|
||||
}()
|
||||
|
|
|
@ -3,13 +3,14 @@ package converter
|
|||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"github.com/anthonynsimon/bild/transform"
|
||||
"image"
|
||||
"image/draw"
|
||||
"image/gif"
|
||||
"image/jpeg"
|
||||
"image/png"
|
||||
"net/http"
|
||||
|
||||
"github.com/anthonynsimon/bild/transform"
|
||||
)
|
||||
|
||||
type Image struct {
|
||||
|
|
Loading…
Reference in New Issue