Skip to content

Commit

Permalink
switched from github.com/pkg/errors to built-in errors (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
vtopc authored Oct 21, 2020
1 parent d81c63d commit 0741b4a
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 24 deletions.
5 changes: 1 addition & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,4 @@ module github.com/vtopc/epoch

go 1.14

require (
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.6.1
)
require github.com/stretchr/testify v1.6.1
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
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/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
Expand Down
5 changes: 2 additions & 3 deletions milliseconds.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package epoch

import (
"encoding/json"
"fmt"
"time"

"github.com/pkg/errors"
)

// Milliseconds - same as epoch.Seconds, but for Epoch(Unix time) in milliseconds.
Expand All @@ -26,7 +25,7 @@ func (m Milliseconds) MarshalJSON() ([]byte, error) {
func (m *Milliseconds) UnmarshalJSON(data []byte) error {
ms, err := parseInt64(string(data))
if err != nil {
return errors.Wrap(err, "failed to parse epoch.Milliseconds")
return fmt.Errorf("failed to parse epoch.Milliseconds: %w", err)
}

m.Time = msToTime(ms)
Expand Down
2 changes: 1 addition & 1 deletion milliseconds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package epoch

import (
"encoding/json"
"errors"
"fmt"
"testing"
"time"

"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down
5 changes: 2 additions & 3 deletions seconds.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package epoch

import (
"encoding/json"
"fmt"
"time"

"github.com/pkg/errors"
)

// Seconds - seconds since the Epoch(Unix time).
Expand All @@ -28,7 +27,7 @@ func (s Seconds) MarshalJSON() ([]byte, error) {
func (s *Seconds) UnmarshalJSON(data []byte) error {
ts, err := parseInt64(string(data))
if err != nil {
return errors.Wrap(err, "failed to parse epoch.Seconds")
return fmt.Errorf("failed to parse epoch.Seconds: %w", err)
}

s.Time = time.Unix(ts, 0)
Expand Down
2 changes: 1 addition & 1 deletion seconds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package epoch

import (
"encoding/json"
"errors"
"fmt"
"testing"
"time"

"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down
7 changes: 3 additions & 4 deletions str_milliseconds.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ package epoch

import (
"encoding/json"
"fmt"
"strconv"
"time"

"github.com/pkg/errors"
)

// StrMilliseconds - same as epoch.Milliseconds, but for strings.
Expand All @@ -30,12 +29,12 @@ func (m *StrMilliseconds) UnmarshalJSON(data []byte) error {

err := json.Unmarshal(data, &v)
if err != nil {
return errors.Wrap(err, "failed to unmarshal epoch.StrMilliseconds")
return fmt.Errorf("failed to unmarshal epoch.StrMilliseconds: %w", err)
}

ms, err := parseInt64(v)
if err != nil {
return errors.Wrap(err, "failed to parse epoch.StrMilliseconds")
return fmt.Errorf("failed to parse epoch.StrMilliseconds: %w", err)
}

m.Time = msToTime(ms)
Expand Down
2 changes: 1 addition & 1 deletion str_milliseconds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package epoch

import (
"encoding/json"
"errors"
"fmt"
"testing"
"time"

"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down
7 changes: 3 additions & 4 deletions str_seconds.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ package epoch

import (
"encoding/json"
"fmt"
"strconv"
"time"

"github.com/pkg/errors"
)

// StrSeconds - seconds since the Epoch(Unix time) as string.
Expand All @@ -31,12 +30,12 @@ func (s *StrSeconds) UnmarshalJSON(data []byte) error {

err := json.Unmarshal(data, &v)
if err != nil {
return errors.Wrap(err, "failed to unmarshal epoch.StrSeconds")
return fmt.Errorf("failed to unmarshal epoch.StrSeconds: %w", err)
}

ts, err := parseInt64(v)
if err != nil {
return errors.Wrap(err, "failed to parse epoch.StrSeconds")
return fmt.Errorf("failed to parse epoch.StrSeconds: %w", err)
}

s.Time = time.Unix(ts, 0)
Expand Down
2 changes: 1 addition & 1 deletion str_seconds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package epoch

import (
"encoding/json"
"errors"
"fmt"
"testing"
"time"

"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down

0 comments on commit 0741b4a

Please sign in to comment.