mirror of
				https://github.com/labstack/echo.git
				synced 2025-10-30 23:57:38 +02:00 
			
		
		
		
	Remove pre Go1.20 support
This commit is contained in:
		| @@ -98,14 +98,14 @@ func (w *bodyDumpResponseWriter) Write(b []byte) (int, error) { | |||||||
| } | } | ||||||
|  |  | ||||||
| func (w *bodyDumpResponseWriter) Flush() { | func (w *bodyDumpResponseWriter) Flush() { | ||||||
| 	err := responseControllerFlush(w.ResponseWriter) | 	err := http.NewResponseController(w.ResponseWriter).Flush() | ||||||
| 	if err != nil && errors.Is(err, http.ErrNotSupported) { | 	if err != nil && errors.Is(err, http.ErrNotSupported) { | ||||||
| 		panic(errors.New("response writer flushing is not supported")) | 		panic(errors.New("response writer flushing is not supported")) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| func (w *bodyDumpResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) { | 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 { | func (w *bodyDumpResponseWriter) Unwrap() http.ResponseWriter { | ||||||
|   | |||||||
| @@ -190,7 +190,7 @@ func (w *gzipResponseWriter) Flush() { | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	w.Writer.(*gzip.Writer).Flush() | 	w.Writer.(*gzip.Writer).Flush() | ||||||
| 	_ = responseControllerFlush(w.ResponseWriter) | 	_ = http.NewResponseController(w.ResponseWriter).Flush() | ||||||
| } | } | ||||||
|  |  | ||||||
| func (w *gzipResponseWriter) Unwrap() http.ResponseWriter { | 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) { | 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 { | func (w *gzipResponseWriter) Push(target string, opts *http.PushOptions) error { | ||||||
|   | |||||||
| @@ -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) |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| @@ -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() |  | ||||||
| } |  | ||||||
| @@ -86,7 +86,7 @@ func (r *Response) Write(b []byte) (n int, err error) { | |||||||
| // buffered data to the client. | // buffered data to the client. | ||||||
| // See [http.Flusher](https://golang.org/pkg/net/http/#Flusher) | // See [http.Flusher](https://golang.org/pkg/net/http/#Flusher) | ||||||
| func (r *Response) Flush() { | func (r *Response) Flush() { | ||||||
| 	err := responseControllerFlush(r.Writer) | 	err := http.NewResponseController(r.Writer).Flush() | ||||||
| 	if err != nil && errors.Is(err, http.ErrNotSupported) { | 	if err != nil && errors.Is(err, http.ErrNotSupported) { | ||||||
| 		panic(errors.New("response writer flushing is not supported")) | 		panic(errors.New("response writer flushing is not supported")) | ||||||
| 	} | 	} | ||||||
| @@ -96,7 +96,7 @@ func (r *Response) Flush() { | |||||||
| // take over the connection. | // take over the connection. | ||||||
| // See [http.Hijacker](https://golang.org/pkg/net/http/#Hijacker) | // See [http.Hijacker](https://golang.org/pkg/net/http/#Hijacker) | ||||||
| func (r *Response) Hijack() (net.Conn, *bufio.ReadWriter, error) { | 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. | // Unwrap returns the original http.ResponseWriter. | ||||||
|   | |||||||
| @@ -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) |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| @@ -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() |  | ||||||
| } |  | ||||||
		Reference in New Issue
	
	Block a user