Skip to content

Commit

Permalink
bugfixes & optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
ex0rcist committed Oct 22, 2024
1 parent 5160e95 commit fb0d79a
Show file tree
Hide file tree
Showing 12 changed files with 210 additions and 178 deletions.
6 changes: 4 additions & 2 deletions coverage.html
Original file line number Diff line number Diff line change
Expand Up @@ -1424,8 +1424,9 @@

import (
"bytes"
"compress/gzip"
"fmt"

"github.com/klauspost/compress/gzip"
)

func Pack(data []byte) (*bytes.Buffer, error) <span class="cov8" title="1">{
Expand All @@ -1451,10 +1452,11 @@
<pre class="file" id="file11" style="display: none">package compression

import (
"compress/gzip"
"context"
"net/http"

"github.com/klauspost/compress/gzip"

"github.com/ex0rcist/metflix/internal/logging"
)

Expand Down
340 changes: 170 additions & 170 deletions coverage.out.tmp

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion internal/compression/compression.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package compression

import (
"bytes"
"compress/gzip"
"fmt"

"github.com/klauspost/compress/gzip"
)

func Pack(data []byte) (*bytes.Buffer, error) {
Expand Down
3 changes: 2 additions & 1 deletion internal/compression/compression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package compression

import (
"bytes"
"compress/gzip"
"io"
"testing"

"github.com/klauspost/compress/gzip"
)

func TestPack_Success(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion internal/compression/compressor.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package compression

import (
"compress/gzip"
"context"
"net/http"

"github.com/klauspost/compress/gzip"

"github.com/ex0rcist/metflix/internal/logging"
)

Expand Down
3 changes: 2 additions & 1 deletion internal/compression/compressor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package compression

import (
"bytes"
"compress/gzip"
"context"
"net/http/httptest"
"testing"

"github.com/klauspost/compress/gzip"
)

func TestCompressor_Write_SupportedContent(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion internal/compression/decompressor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package compression

import (
"bytes"
"compress/gzip"
"context"
"errors"
"io"

"github.com/klauspost/compress/gzip"

"github.com/ex0rcist/metflix/internal/entities"

"net/http"
Expand Down
27 changes: 26 additions & 1 deletion internal/middleware/compression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,38 @@ package middleware

import (
"bytes"
"compress/gzip"

"io"
"net/http"
"net/http/httptest"
"testing"

"github.com/klauspost/compress/gzip"
)

func benchFn(data []byte) {
// data := []byte("test data")

nextHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write(data)
})

req := httptest.NewRequest(http.MethodGet, "/", nil)
req.Header.Set("Accept-Encoding", "gzip")

rr := httptest.NewRecorder()
handler := CompressResponse(nextHandler)
handler.ServeHTTP(rr, req)
}

func BenchmarkCompression(b *testing.B) {
payload := []byte("test data")
for i := 0; i < b.N; i++ {
benchFn(payload)
}
}

func TestDecompressRequest_Success(t *testing.T) {
data := []byte("test data")
var buf bytes.Buffer
Expand Down
Binary file modified profiles/base.prof
Binary file not shown.
Binary file removed profiles/random/base.pprof
Binary file not shown.
Binary file removed profiles/random/result.pprof
Binary file not shown.
Binary file modified profiles/result.prof
Binary file not shown.

0 comments on commit fb0d79a

Please sign in to comment.