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

refactor(deps): replaced external pkg/errors with built-in errors package #168

Merged
merged 3 commits into from
Dec 23, 2023
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This is the [Go](http://golang.org) implementation of **Frisbee**, a bring-your-
protocol messaging framework designed for performance and
stability.

**This library requires Go1.18 or later.**
**This library requires Go1.20 or later.**

## Important note about releases and stability

Expand Down
9 changes: 5 additions & 4 deletions async.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@ import (
"context"
"crypto/tls"
"encoding/binary"
"errors"
"net"
"sync"
"time"

"github.com/loopholelabs/common/pkg/queue"
"github.com/loopholelabs/frisbee-go/internal/dialer"
"github.com/loopholelabs/frisbee-go/pkg/metadata"
"github.com/loopholelabs/frisbee-go/pkg/packet"
"github.com/pkg/errors"
"github.com/rs/zerolog"
"go.uber.org/atomic"
"net"
"sync"
"time"
)

// Async is the underlying asynchronous frisbee connection which has extremely efficient read and write logic and
Expand Down
7 changes: 4 additions & 3 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ package frisbee
import (
"context"
"crypto/tls"
"github.com/loopholelabs/frisbee-go/pkg/packet"
"github.com/pkg/errors"
"github.com/rs/zerolog"
"errors"
"io"
"net"
"time"

"github.com/loopholelabs/frisbee-go/pkg/packet"
"github.com/rs/zerolog"
)

// DefaultBufferSize is the size of the default buffer
Expand Down
5 changes: 3 additions & 2 deletions frisbee.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ package frisbee

import (
"context"
"errors"
"time"

"github.com/loopholelabs/frisbee-go/pkg/metadata"
"github.com/loopholelabs/frisbee-go/pkg/packet"
"github.com/loopholelabs/polyglot"
"github.com/pkg/errors"
"time"
)

// These are various frisbee errors that can be returned by the client or server:
Expand Down
15 changes: 7 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
module github.com/loopholelabs/frisbee-go

go 1.18
go 1.20

require (
github.com/loopholelabs/common v0.4.9
github.com/loopholelabs/polyglot v1.1.2
github.com/loopholelabs/polyglot v1.1.4
github.com/loopholelabs/testing v0.2.3
github.com/pkg/errors v0.9.1
github.com/rs/zerolog v1.30.0
github.com/rs/zerolog v1.31.0
github.com/stretchr/testify v1.8.4
go.uber.org/atomic v1.11.0
go.uber.org/goleak v1.2.1
go.uber.org/goleak v1.3.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
golang.org/x/sys v0.15.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
32 changes: 17 additions & 15 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,33 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/loopholelabs/common v0.4.9 h1:9MPUYlZZ/qx3Kt8LXgXxcSXthrM91od8026c4DlGpAU=
github.com/loopholelabs/common v0.4.9/go.mod h1:Wop5srN1wYT+mdQ9gZ+kn2I9qKAyVd0FB48pThwIa9M=
github.com/loopholelabs/polyglot v1.1.2 h1:9JE1m/IL8rgWIlykvebz98i4tjOGNOpgGIB3CqbfvrE=
github.com/loopholelabs/polyglot v1.1.2/go.mod h1:EA88BEkIluKHAWxhyOV88xXz68YkRdo9IzZ+1dj+7Ao=
github.com/loopholelabs/polyglot v1.1.4 h1:+yCGD3MQnmmX5ln+9mCbSCUgH7GQH0RxKJn/54hAaQU=
github.com/loopholelabs/polyglot v1.1.4/go.mod h1:EA88BEkIluKHAWxhyOV88xXz68YkRdo9IzZ+1dj+7Ao=
github.com/loopholelabs/testing v0.2.3 h1:4nVuK5ctaE6ua5Z0dYk2l7xTFmcpCYLUeGjRBp8keOA=
github.com/loopholelabs/testing v0.2.3/go.mod h1:gqtGY91soYD1fQoKQt/6kP14OYpS7gcbcIgq5mc9m8Q=
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.30.0 h1:SymVODrcRsaRaSInD9yQtKbtWqwsfoPcRff/oRXLj4c=
github.com/rs/zerolog v1.30.0/go.mod h1:/tk+P47gFdPXq4QYjvCmT5/Gsug2nagsFWBWhAiSi1w=
github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A=
github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A=
go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
15 changes: 7 additions & 8 deletions pkg/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ package metadata

import (
"encoding/binary"
"errors"
"unsafe"

"github.com/pkg/errors"
)

var (
Encoding = errors.New("error while encoding metadata")
Decoding = errors.New("error while decoding metadata")
InvalidBufferLength = errors.New("invalid buffer length")
EncodingErr = errors.New("error while encoding metadata")
DecodingErr = errors.New("error while decoding metadata")
InvalidBufferLengthErr = errors.New("invalid buffer length")
)

const (
Expand Down Expand Up @@ -59,7 +58,7 @@ type Metadata struct {
func (fm *Metadata) Encode() (b *Buffer, err error) {
defer func() {
if recoveredErr := recover(); recoveredErr != nil {
err = errors.Wrap(recoveredErr.(error), Encoding.Error())
err = errors.Join(recoveredErr.(error), EncodingErr)
}
}()

Expand All @@ -75,7 +74,7 @@ func (fm *Metadata) Encode() (b *Buffer, err error) {
func (fm *Metadata) Decode(buf *Buffer) (err error) {
defer func() {
if recoveredErr := recover(); recoveredErr != nil {
err = errors.Wrap(recoveredErr.(error), Decoding.Error())
err = errors.Join(recoveredErr.(error), DecodingErr)
}
}()

Expand All @@ -98,7 +97,7 @@ func Encode(id, operation uint16, contentLength uint32) (*Buffer, error) {

func Decode(buf []byte) (*Metadata, error) {
if len(buf) < Size {
return nil, InvalidBufferLength
return nil, InvalidBufferLengthErr
}

m := new(Metadata)
Expand Down
5 changes: 3 additions & 2 deletions pkg/metadata/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ package metadata

import (
"encoding/binary"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"testing"
)

func TestMessageEncodeDecode(t *testing.T) {
Expand Down Expand Up @@ -72,7 +73,7 @@ func TestEncodeDecode(t *testing.T) {

invalidMessage, err := Decode(emptyEncodedBytes[1:])
require.Error(t, err)
assert.ErrorIs(t, InvalidBufferLength, err)
assert.ErrorIs(t, InvalidBufferLengthErr, err)
assert.Nil(t, invalidMessage)
}

Expand Down
2 changes: 1 addition & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ package frisbee
import (
"context"
"crypto/tls"
"errors"
"net"
"sync"
"time"

"github.com/loopholelabs/frisbee-go/pkg/packet"
"github.com/pkg/errors"
"github.com/rs/zerolog"
"go.uber.org/atomic"
)
Expand Down
2 changes: 1 addition & 1 deletion sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"crypto/tls"
"encoding/binary"
"errors"
"io"
"net"
"sync"
Expand All @@ -28,7 +29,6 @@ import (
"github.com/loopholelabs/frisbee-go/internal/dialer"
"github.com/loopholelabs/frisbee-go/pkg/metadata"
"github.com/loopholelabs/frisbee-go/pkg/packet"
"github.com/pkg/errors"
"github.com/rs/zerolog"
"go.uber.org/atomic"
)
Expand Down
Loading