Skip to content

Commit

Permalink
Use Go standard library errors package (#45)
Browse files Browse the repository at this point in the history
Replace the deprecated and archived `github.com/pkg/errors` package with
the Go standard library `errors` package and `%w` wrapping so it can be
used with `errors.Is()`.
* Bump minimum Go version to 1.19 to automatically include transitive
  dependencies in the Go modules files.

Signed-off-by: SuperQ <superq@gmail.com>
  • Loading branch information
SuperQ committed Aug 18, 2024
1 parent b0b9070 commit 515964d
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 57 deletions.
9 changes: 7 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
module github.com/lestrrat-go/strftime

go 1.13
go 1.19

require (
github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.8.4
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
9 changes: 0 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc h1:RKf14vYWi2ttpEmkA4aQ3j4u9dStX2t4M8UM6qqNsG8=
github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc/go.mod h1:kopuH9ugFRkIXf3YoqHKyrJ9YfUFsckUU9S7B+XP+is=
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/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
18 changes: 0 additions & 18 deletions internal/errors/errors_fmt.go

This file was deleted.

18 changes: 0 additions & 18 deletions internal/errors/errors_pkg.go

This file was deleted.

5 changes: 2 additions & 3 deletions specifications.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package strftime

import (
"errors"
"fmt"
"sync"

"github.com/lestrrat-go/strftime/internal/errors"
)

// because there is no such thing was a sync.RWLocker
Expand Down Expand Up @@ -124,7 +123,7 @@ func (ds *specificationSet) Lookup(b byte) (Appender, error) {
}
v, ok := ds.store[b]
if !ok {
return nil, errors.Errorf(`lookup failed: '%%%c' was not found in specification set`, b)
return nil, fmt.Errorf(`lookup failed: '%%%c' was not found in specification set`, b)
}
return v, nil
}
Expand Down
14 changes: 7 additions & 7 deletions strftime.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package strftime

import (
"errors"
"fmt"
"io"
"strings"
"sync"
"time"

"github.com/lestrrat-go/strftime/internal/errors"
)

type compileHandler interface {
Expand Down Expand Up @@ -62,7 +62,7 @@ func compile(handler compileHandler, p string, ds SpecificationSet) error {

specification, err := ds.Lookup(p[1])
if err != nil {
return errors.Wrap(err, `pattern compilation failed`)
return fmt.Errorf("pattern compilation failed: %w", err)
}

handler.handle(specification)
Expand Down Expand Up @@ -127,14 +127,14 @@ func Format(p string, t time.Time, options ...Option) (string, error) {
// TODO: this may be premature optimization
ds, err := getSpecificationSetFor(options...)
if err != nil {
return "", errors.Wrap(err, `failed to get specification set`)
return "", fmt.Errorf("failed to get specification set: %w", err)
}
h := getFmtAppendExecutor()
defer releasdeFmtAppendExecutor(h)

h.t = t
if err := compile(h, p, ds); err != nil {
return "", errors.Wrap(err, `failed to compile format`)
return "", fmt.Errorf("failed to compile format: %w", err)
}

return string(h.dst), nil
Expand All @@ -152,14 +152,14 @@ func New(p string, options ...Option) (*Strftime, error) {
// TODO: this may be premature optimization
ds, err := getSpecificationSetFor(options...)
if err != nil {
return nil, errors.Wrap(err, `failed to get specification set`)
return nil, fmt.Errorf("failed to get specification set: %w", err)
}

var h appenderListBuilder
h.list = &combiningAppend{}

if err := compile(&h, p, ds); err != nil {
return nil, errors.Wrap(err, `failed to compile format`)
return nil, fmt.Errorf("failed to compile format: %w", err)
}

return &Strftime{
Expand Down

0 comments on commit 515964d

Please sign in to comment.