diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml index 7909ee7..9196a22 100644 --- a/.github/workflows/CI.yaml +++ b/.github/workflows/CI.yaml @@ -19,7 +19,7 @@ jobs: - name: Install Go uses: actions/setup-go@v3 with: - go-version: '1.21' + go-version: '1.22' - name: Setup necessary packages run: | diff --git a/.github/workflows/codecov.yaml b/.github/workflows/codecov.yaml index 5efd2c3..ef5651a 100644 --- a/.github/workflows/codecov.yaml +++ b/.github/workflows/codecov.yaml @@ -19,7 +19,7 @@ jobs: - name: Install Go uses: actions/setup-go@v3 with: - go-version: '1.21' + go-version: '1.22' - name: Setup necessary packages run: | diff --git a/Dockerfile b/Dockerfile index 3bdd0f5..e905ab8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.21-bookworm as builder +FROM golang:1.22-bookworm as builder ARG IMG_PATH=/opt/pics ARG EXHAUST_PATH=/opt/exhaust diff --git a/encoder/encoder.go b/encoder/encoder.go index b3cd2fd..c7c6047 100644 --- a/encoder/encoder.go +++ b/encoder/encoder.go @@ -187,7 +187,7 @@ func webpEncoder(img *vips.ImageRef, rawPath string, optimizedPath string, extra Lossless: false, StripMetadata: true, } - for i := 0; i <= 6; i++ { + for i := range 7 { ep.ReductionEffort = i buf, _, err = img.ExportWebp(&ep) if err != nil && strings.Contains(err.Error(), "unable to encode") { diff --git a/encoder/prefetch.go b/encoder/prefetch.go index c841aea..ec31975 100644 --- a/encoder/prefetch.go +++ b/encoder/prefetch.go @@ -18,7 +18,7 @@ func PrefetchImages() { var sTime = time.Now() log.Infof("Prefetching using %d cores", config.Jobs) var finishChan = make(chan int, config.Jobs) - for i := 0; i < config.Jobs; i++ { + for _ = range config.Jobs { finishChan <- 1 } diff --git a/go.mod b/go.mod index 1d41cf7..de77c41 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module webp_server_go -go 1.21 +go 1.22 require ( github.com/cespare/xxhash v1.1.0 diff --git a/handler/router_test.go b/handler/router_test.go index aa397de..cd1cf73 100644 --- a/handler/router_test.go +++ b/handler/router_test.go @@ -100,7 +100,7 @@ func TestConvertDuplicates(t *testing.T) { // test Chrome for url, respType := range testLink { - for i := 0; i < N; i++ { + for _ = range N { resp, data := requestToServer(url, app, chromeUA, acceptWebP) defer resp.Body.Close() contentType := helper.GetContentType(data) @@ -220,12 +220,12 @@ func TestConvertProxyModeBad(t *testing.T) { func TestConvertProxyModeWork(t *testing.T) { setupParam() config.ProxyMode = true - config.Config.ImgPath = "https://webp.sh" + config.Config.ImgPath = "https://docs.webp.sh" var app = fiber.New() app.Get("/*", Convert) - url := "http://127.0.0.1:3333/images/cover.jpg" + url := "http://127.0.0.1:3333/images/webp_server.jpg" resp, data := requestToServer(url, app, chromeUA, acceptWebP) defer resp.Body.Close() @@ -244,28 +244,28 @@ func TestConvertProxyImgMap(t *testing.T) { config.ProxyMode = false config.Config.ImageMap = map[string]string{ "/2": "../pics/dir1", - "/3": "../pics3", // Invalid path, does not exists - "www.invalid-path.com": "https://webp.sh", // Invalid, it does not start with '/' - "/www.weird-path.com": "https://webp.sh", - "/www.even-more-werid-path.com": "https://webp.sh/images", - "http://example.com": "https://webp.sh", + "/3": "../pics3", // Invalid path, does not exists + "www.invalid-path.com": "https://docs.webp.sh", // Invalid, it does not start with '/' + "/www.weird-path.com": "https://docs.webp.sh", + "/www.even-more-werid-path.com": "https://docs.webp.sh/images", + "http://example.com": "https://docs.webp.sh", } var app = fiber.New() app.Get("/*", Convert) var testUrls = map[string]string{ - "http://127.0.0.1:3333/webp_server.jpg": "image/webp", - "http://127.0.0.1:3333/2/inside.jpg": "image/webp", - "http://127.0.0.1:3333/www.weird-path.com/images/cover.jpg": "image/webp", - "http://127.0.0.1:3333/www.even-more-werid-path.com/cover.jpg": "image/webp", - "http://example.com/images/cover.jpg": "image/webp", + "http://127.0.0.1:3333/webp_server.jpg": "image/webp", + "http://127.0.0.1:3333/2/inside.jpg": "image/webp", + "http://127.0.0.1:3333/www.weird-path.com/images/webp_server.jpg": "image/webp", + "http://127.0.0.1:3333/www.even-more-werid-path.com/webp_server.jpg": "image/webp", + "http://example.com//images/webp_server.jpg": "image/webp", } var testUrlsLegacy = map[string]string{ - "http://127.0.0.1:3333/webp_server.jpg": "image/jpeg", - "http://127.0.0.1:3333/2/inside.jpg": "image/jpeg", - "http://example.com/images/cover.jpg": "image/jpeg", + "http://127.0.0.1:3333/webp_server.jpg": "image/jpeg", + "http://127.0.0.1:3333/2/inside.jpg": "image/jpeg", + "http://example.com/images/webp_server.jpg": "image/jpeg", } var testUrlsInvalid = map[string]string{ @@ -304,17 +304,17 @@ func TestConvertProxyImgMapCWD(t *testing.T) { "/1": "../pics/dir1", "/2": "../pics", "/3": "../pics", // Invalid path, does not exists - "http://www.example.com": "https://webp.sh", + "http://www.example.com": "https://docs.webp.sh", } var app = fiber.New() app.Get("/*", Convert) var testUrls = map[string]string{ - "http://127.0.0.1:3333/1/inside.jpg": "image/webp", - "http://127.0.0.1:3333/2/webp_server.jpg": "image/webp", - "http://127.0.0.1:3333/3/webp_server.jpg": "image/webp", - "http://www.example.com/images/cover.jpg": "image/webp", + "http://127.0.0.1:3333/1/inside.jpg": "image/webp", + "http://127.0.0.1:3333/2/webp_server.jpg": "image/webp", + "http://127.0.0.1:3333/3/webp_server.jpg": "image/webp", + "http://www.example.com/images/webp_server.jpg": "image/webp", } for url, respType := range testUrls {