Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Go 1.22 #311

Merged
merged 3 commits into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codecov.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion encoder/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
2 changes: 1 addition & 1 deletion encoder/prefetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module webp_server_go

go 1.21
go 1.22

require (
github.com/cespare/xxhash v1.1.0
Expand Down
42 changes: 21 additions & 21 deletions handler/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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{
Expand Down Expand Up @@ -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 {
Expand Down
Loading