Skip to content

Commit

Permalink
remove pkg/errors
Browse files Browse the repository at this point in the history
  • Loading branch information
lestrrat committed Mar 29, 2022
1 parent e7e8fea commit a997830
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 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/lestrrat-go/httpcc

go 1.16

require (
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.6.1
)
require github.com/stretchr/testify v1.7.1
11 changes: 11 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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/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/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
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 h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
29 changes: 14 additions & 15 deletions httpcc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package httpcc

import (
"bufio"
"fmt"
"strconv"
"strings"
"unicode/utf8"

"github.com/pkg/errors"
)

const (
Expand Down Expand Up @@ -103,28 +102,28 @@ func parseDirective(s string, ccd directiveValidator) (*TokenPair, error) {
switch ccd.Validate(pair.Name) {
case TokenOnly:
if v[0] == '"' {
return nil, errors.Errorf(`invalid value for %s (quoted string not allowed)`, pair.Name)
return nil, fmt.Errorf(`invalid value for %s (quoted string not allowed)`, pair.Name)
}
case QuotedStringOnly: // quoted-string only
if v[0] != '"' {
return nil, errors.Errorf(`invalid value for %s (bare token not allowed)`, pair.Name)
return nil, fmt.Errorf(`invalid value for %s (bare token not allowed)`, pair.Name)
}
tmp, err := strconv.Unquote(v)
if err != nil {
return nil, errors.Errorf(`malformed quoted string in token`)
return nil, fmt.Errorf(`malformed quoted string in token`)
}
v = tmp
case AnyTokenValue:
if v[0] == '"' {
tmp, err := strconv.Unquote(v)
if err != nil {
return nil, errors.Errorf(`malformed quoted string in token`)
return nil, fmt.Errorf(`malformed quoted string in token`)
}
v = tmp
}
case NoArgument:
if len(v) > 0 {
return nil, errors.Errorf(`received argument to directive %s`, pair.Name)
return nil, fmt.Errorf(`received argument to directive %s`, pair.Name)
}
}

Expand All @@ -148,7 +147,7 @@ func parseDirectives(s string, p func(string) (*TokenPair, error)) ([]*TokenPair
for scanner.Scan() {
tok, err := p(scanner.Text())
if err != nil {
return nil, errors.Wrapf(err, `failed to parse token #%d`, len(tokens)+1)
return nil, fmt.Errorf(`failed to parse token #%d: %w`, len(tokens)+1, err)
}
tokens = append(tokens, tok)
}
Expand Down Expand Up @@ -220,7 +219,7 @@ func ParseRequest(v string) (*RequestDirective, error) {
var dir RequestDirective
tokens, err := ParseRequestDirectives(v)
if err != nil {
return nil, errors.Wrap(err, `failed to parse tokens`)
return nil, fmt.Errorf(`failed to parse tokens: %w`, err)
}

for _, token := range tokens {
Expand All @@ -229,19 +228,19 @@ func ParseRequest(v string) (*RequestDirective, error) {
case MaxAge:
iv, err := strconv.ParseUint(token.Value, 10, 64)
if err != nil {
return nil, errors.Wrap(err, `failed to parse max-age`)
return nil, fmt.Errorf(`failed to parse max-age: %w`, err)
}
dir.maxAge = &iv
case MaxStale:
iv, err := strconv.ParseUint(token.Value, 10, 64)
if err != nil {
return nil, errors.Wrap(err, `failed to parse max-stale`)
return nil, fmt.Errorf(`failed to parse max-stale: %w`, err)
}
dir.maxStale = &iv
case MinFresh:
iv, err := strconv.ParseUint(token.Value, 10, 64)
if err != nil {
return nil, errors.Wrap(err, `failed to parse min-fresh`)
return nil, fmt.Errorf(`failed to parse min-fresh: %w`, err)
}
dir.minFresh = &iv
case NoCache:
Expand All @@ -263,7 +262,7 @@ func ParseRequest(v string) (*RequestDirective, error) {
func ParseResponse(v string) (*ResponseDirective, error) {
tokens, err := ParseResponseDirectives(v)
if err != nil {
return nil, errors.Wrap(err, `failed to parse tokens`)
return nil, fmt.Errorf(`failed to parse tokens: %w`, err)
}

var dir ResponseDirective
Expand All @@ -274,7 +273,7 @@ func ParseResponse(v string) (*ResponseDirective, error) {
case MaxAge:
iv, err := strconv.ParseUint(token.Value, 10, 64)
if err != nil {
return nil, errors.Wrap(err, `failed to parse max-age`)
return nil, fmt.Errorf(`failed to parse max-age: %w`, err)
}
dir.maxAge = &iv
case NoCache:
Expand All @@ -300,7 +299,7 @@ func ParseResponse(v string) (*ResponseDirective, error) {
case SMaxAge:
iv, err := strconv.ParseUint(token.Value, 10, 64)
if err != nil {
return nil, errors.Wrap(err, `failed to parse s-maxage`)
return nil, fmt.Errorf(`failed to parse s-maxage: %w`, err)
}
dir.sMaxAge = &iv
default:
Expand Down

0 comments on commit a997830

Please sign in to comment.