11package main
22
33import (
4- "compress/flate"
5- "compress/gzip"
64 "context"
75 "database/sql"
86 "encoding/json"
@@ -18,6 +16,7 @@ import (
1816
1917 "github.com/jackc/pgx/v5/pgxpool"
2018 "github.com/labstack/echo/v4"
19+ "github.com/labstack/echo/v4/middleware"
2120 _ "modernc.org/sqlite"
2221)
2322
@@ -172,6 +171,10 @@ func main() {
172171 e .HideBanner = true
173172 e .HidePort = true
174173
174+ gzipMiddleware := middleware .GzipWithConfig (middleware.GzipConfig {
175+ Level : 1 ,
176+ })
177+
175178 e .GET ("/pipeline" , func (c echo.Context ) error {
176179 c .Response ().Header ().Set ("Server" , "echo" )
177180 return c .String (http .StatusOK , "ok" )
@@ -214,30 +217,8 @@ func main() {
214217
215218 e .GET ("/compression" , func (c echo.Context ) error {
216219 c .Response ().Header ().Set ("Server" , "echo" )
217- ae := c .Request ().Header .Get ("Accept-Encoding" )
218- if strings .Contains (ae , "deflate" ) {
219- c .Response ().Header ().Set ("Content-Type" , "application/json" )
220- c .Response ().Header ().Set ("Content-Encoding" , "deflate" )
221- c .Response ().WriteHeader (http .StatusOK )
222- w , err := flate .NewWriter (c .Response (), flate .BestSpeed )
223- if err == nil {
224- w .Write (jsonLargeResponse )
225- w .Close ()
226- }
227- return nil
228- } else if strings .Contains (ae , "gzip" ) {
229- c .Response ().Header ().Set ("Content-Type" , "application/json" )
230- c .Response ().Header ().Set ("Content-Encoding" , "gzip" )
231- c .Response ().WriteHeader (http .StatusOK )
232- w , err := gzip .NewWriterLevel (c .Response (), gzip .BestSpeed )
233- if err == nil {
234- w .Write (jsonLargeResponse )
235- w .Close ()
236- }
237- return nil
238- }
239220 return c .Blob (http .StatusOK , "application/json" , jsonLargeResponse )
240- })
221+ }, gzipMiddleware )
241222
242223 e .POST ("/upload" , func (c echo.Context ) error {
243224 size , _ := io .Copy (io .Discard , c .Request ().Body )
0 commit comments