From 9a9761fc3b913e7ba3bc13d4cc8821ede4393441 Mon Sep 17 00:00:00 2001 From: toimtoimtoim Date: Thu, 15 Aug 2024 13:36:24 +0300 Subject: [PATCH 1/3] Add Go 1.23 to CI --- .github/workflows/checks.yml | 2 +- .github/workflows/echo.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 9ae5dbd5a..027b5de55 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -14,7 +14,7 @@ permissions: env: # run static analysis only with the latest Go version - LATEST_GO_VERSION: "1.22" + LATEST_GO_VERSION: "1.23" jobs: check: diff --git a/.github/workflows/echo.yml b/.github/workflows/echo.yml index cb3dc448b..ef83dfcd0 100644 --- a/.github/workflows/echo.yml +++ b/.github/workflows/echo.yml @@ -14,7 +14,7 @@ permissions: env: # run coverage and benchmarks only with the latest Go version - LATEST_GO_VERSION: "1.22" + LATEST_GO_VERSION: "1.23" jobs: test: @@ -25,7 +25,7 @@ jobs: # Echo tests with last four major releases (unless there are pressing vulnerabilities) # As we depend on `golang.org/x/` libraries which only support last 2 Go releases we could have situations when # we derive from last four major releases promise. - go: ["1.19", "1.20", "1.21", "1.22"] + go: ["1.20", "1.21", "1.22", "1.23"] name: ${{ matrix.os }} @ Go ${{ matrix.go }} runs-on: ${{ matrix.os }} steps: From 5e3bcc042822bb428b77d74eb7e02d1ad9e33b72 Mon Sep 17 00:00:00 2001 From: toimtoimtoim Date: Thu, 15 Aug 2024 14:13:58 +0300 Subject: [PATCH 2/3] tests: In Go 1.23 fs related errors have changed. --- echo_fs_test.go | 17 +++++++---------- group_fs_test.go | 17 +++++++---------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/echo_fs_test.go b/echo_fs_test.go index e882a0682..ab8faa7fa 100644 --- a/echo_fs_test.go +++ b/echo_fs_test.go @@ -245,19 +245,16 @@ func TestEcho_FileFS(t *testing.T) { func TestEcho_StaticPanic(t *testing.T) { var testCases = []struct { - name string - givenRoot string - expectError string + name string + givenRoot string }{ { - name: "panics for ../", - givenRoot: "../assets", - expectError: "can not create sub FS, invalid root given, err: sub ../assets: invalid name", + name: "panics for ../", + givenRoot: "../assets", }, { - name: "panics for /", - givenRoot: "/assets", - expectError: "can not create sub FS, invalid root given, err: sub /assets: invalid name", + name: "panics for /", + givenRoot: "/assets", }, } @@ -266,7 +263,7 @@ func TestEcho_StaticPanic(t *testing.T) { e := New() e.Filesystem = os.DirFS("./") - assert.PanicsWithError(t, tc.expectError, func() { + assert.Panics(t, func() { e.Static("../assets", tc.givenRoot) }) }) diff --git a/group_fs_test.go b/group_fs_test.go index 8bcd547d1..caa200940 100644 --- a/group_fs_test.go +++ b/group_fs_test.go @@ -75,19 +75,16 @@ func TestGroup_FileFS(t *testing.T) { func TestGroup_StaticPanic(t *testing.T) { var testCases = []struct { - name string - givenRoot string - expectError string + name string + givenRoot string }{ { - name: "panics for ../", - givenRoot: "../images", - expectError: "can not create sub FS, invalid root given, err: sub ../images: invalid name", + name: "panics for ../", + givenRoot: "../images", }, { - name: "panics for /", - givenRoot: "/images", - expectError: "can not create sub FS, invalid root given, err: sub /images: invalid name", + name: "panics for /", + givenRoot: "/images", }, } @@ -98,7 +95,7 @@ func TestGroup_StaticPanic(t *testing.T) { g := e.Group("/assets") - assert.PanicsWithError(t, tc.expectError, func() { + assert.Panics(t, func() { g.Static("/images", tc.givenRoot) }) }) From 090bde51308139e4205bfc5a06fdfb703f0719b0 Mon Sep 17 00:00:00 2001 From: toimtoimtoim Date: Thu, 15 Aug 2024 14:25:35 +0300 Subject: [PATCH 3/3] Remove pre Go1.20 support --- middleware/body_dump.go | 4 +-- middleware/compress.go | 4 +-- middleware/responsecontroller_1.19.go | 44 --------------------------- middleware/responsecontroller_1.20.go | 20 ------------ response.go | 4 +-- responsecontroller_1.19.go | 44 --------------------------- responsecontroller_1.20.go | 20 ------------ 7 files changed, 6 insertions(+), 134 deletions(-) delete mode 100644 middleware/responsecontroller_1.19.go delete mode 100644 middleware/responsecontroller_1.20.go delete mode 100644 responsecontroller_1.19.go delete mode 100644 responsecontroller_1.20.go diff --git a/middleware/body_dump.go b/middleware/body_dump.go index b06f76202..e4119ec1e 100644 --- a/middleware/body_dump.go +++ b/middleware/body_dump.go @@ -98,14 +98,14 @@ func (w *bodyDumpResponseWriter) Write(b []byte) (int, error) { } func (w *bodyDumpResponseWriter) Flush() { - err := responseControllerFlush(w.ResponseWriter) + err := http.NewResponseController(w.ResponseWriter).Flush() if err != nil && errors.Is(err, http.ErrNotSupported) { panic(errors.New("response writer flushing is not supported")) } } func (w *bodyDumpResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) { - return responseControllerHijack(w.ResponseWriter) + return http.NewResponseController(w.ResponseWriter).Hijack() } func (w *bodyDumpResponseWriter) Unwrap() http.ResponseWriter { diff --git a/middleware/compress.go b/middleware/compress.go index 557bdc8e2..012b76b01 100644 --- a/middleware/compress.go +++ b/middleware/compress.go @@ -190,7 +190,7 @@ func (w *gzipResponseWriter) Flush() { } w.Writer.(*gzip.Writer).Flush() - _ = responseControllerFlush(w.ResponseWriter) + _ = http.NewResponseController(w.ResponseWriter).Flush() } func (w *gzipResponseWriter) Unwrap() http.ResponseWriter { @@ -198,7 +198,7 @@ func (w *gzipResponseWriter) Unwrap() http.ResponseWriter { } func (w *gzipResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) { - return responseControllerHijack(w.ResponseWriter) + return http.NewResponseController(w.ResponseWriter).Hijack() } func (w *gzipResponseWriter) Push(target string, opts *http.PushOptions) error { diff --git a/middleware/responsecontroller_1.19.go b/middleware/responsecontroller_1.19.go deleted file mode 100644 index ddf6b64c0..000000000 --- a/middleware/responsecontroller_1.19.go +++ /dev/null @@ -1,44 +0,0 @@ -// SPDX-License-Identifier: MIT -// SPDX-FileCopyrightText: © 2015 LabStack LLC and Echo contributors - -//go:build !go1.20 - -package middleware - -import ( - "bufio" - "fmt" - "net" - "net/http" -) - -// TODO: remove when Go 1.23 is released and we do not support 1.19 anymore -func responseControllerFlush(rw http.ResponseWriter) error { - for { - switch t := rw.(type) { - case interface{ FlushError() error }: - return t.FlushError() - case http.Flusher: - t.Flush() - return nil - case interface{ Unwrap() http.ResponseWriter }: - rw = t.Unwrap() - default: - return fmt.Errorf("%w", http.ErrNotSupported) - } - } -} - -// TODO: remove when Go 1.23 is released and we do not support 1.19 anymore -func responseControllerHijack(rw http.ResponseWriter) (net.Conn, *bufio.ReadWriter, error) { - for { - switch t := rw.(type) { - case http.Hijacker: - return t.Hijack() - case interface{ Unwrap() http.ResponseWriter }: - rw = t.Unwrap() - default: - return nil, nil, fmt.Errorf("%w", http.ErrNotSupported) - } - } -} diff --git a/middleware/responsecontroller_1.20.go b/middleware/responsecontroller_1.20.go deleted file mode 100644 index bc03059bc..000000000 --- a/middleware/responsecontroller_1.20.go +++ /dev/null @@ -1,20 +0,0 @@ -// SPDX-License-Identifier: MIT -// SPDX-FileCopyrightText: © 2015 LabStack LLC and Echo contributors - -//go:build go1.20 - -package middleware - -import ( - "bufio" - "net" - "net/http" -) - -func responseControllerFlush(rw http.ResponseWriter) error { - return http.NewResponseController(rw).Flush() -} - -func responseControllerHijack(rw http.ResponseWriter) (net.Conn, *bufio.ReadWriter, error) { - return http.NewResponseController(rw).Hijack() -} diff --git a/response.go b/response.go index a40072dc2..0f174536d 100644 --- a/response.go +++ b/response.go @@ -86,7 +86,7 @@ func (r *Response) Write(b []byte) (n int, err error) { // buffered data to the client. // See [http.Flusher](https://golang.org/pkg/net/http/#Flusher) func (r *Response) Flush() { - err := responseControllerFlush(r.Writer) + err := http.NewResponseController(r.Writer).Flush() if err != nil && errors.Is(err, http.ErrNotSupported) { panic(errors.New("response writer flushing is not supported")) } @@ -96,7 +96,7 @@ func (r *Response) Flush() { // take over the connection. // See [http.Hijacker](https://golang.org/pkg/net/http/#Hijacker) func (r *Response) Hijack() (net.Conn, *bufio.ReadWriter, error) { - return responseControllerHijack(r.Writer) + return http.NewResponseController(r.Writer).Hijack() } // Unwrap returns the original http.ResponseWriter. diff --git a/responsecontroller_1.19.go b/responsecontroller_1.19.go deleted file mode 100644 index 782dab3a3..000000000 --- a/responsecontroller_1.19.go +++ /dev/null @@ -1,44 +0,0 @@ -// SPDX-License-Identifier: MIT -// SPDX-FileCopyrightText: © 2015 LabStack LLC and Echo contributors - -//go:build !go1.20 - -package echo - -import ( - "bufio" - "fmt" - "net" - "net/http" -) - -// TODO: remove when Go 1.23 is released and we do not support 1.19 anymore -func responseControllerFlush(rw http.ResponseWriter) error { - for { - switch t := rw.(type) { - case interface{ FlushError() error }: - return t.FlushError() - case http.Flusher: - t.Flush() - return nil - case interface{ Unwrap() http.ResponseWriter }: - rw = t.Unwrap() - default: - return fmt.Errorf("%w", http.ErrNotSupported) - } - } -} - -// TODO: remove when Go 1.23 is released and we do not support 1.19 anymore -func responseControllerHijack(rw http.ResponseWriter) (net.Conn, *bufio.ReadWriter, error) { - for { - switch t := rw.(type) { - case http.Hijacker: - return t.Hijack() - case interface{ Unwrap() http.ResponseWriter }: - rw = t.Unwrap() - default: - return nil, nil, fmt.Errorf("%w", http.ErrNotSupported) - } - } -} diff --git a/responsecontroller_1.20.go b/responsecontroller_1.20.go deleted file mode 100644 index 6d77c07f8..000000000 --- a/responsecontroller_1.20.go +++ /dev/null @@ -1,20 +0,0 @@ -// SPDX-License-Identifier: MIT -// SPDX-FileCopyrightText: © 2015 LabStack LLC and Echo contributors - -//go:build go1.20 - -package echo - -import ( - "bufio" - "net" - "net/http" -) - -func responseControllerFlush(rw http.ResponseWriter) error { - return http.NewResponseController(rw).Flush() -} - -func responseControllerHijack(rw http.ResponseWriter) (net.Conn, *bufio.ReadWriter, error) { - return http.NewResponseController(rw).Hijack() -}