Skip to content

Commit

Permalink
Use any instead of interface{} (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
cristaloleg authored Nov 7, 2023
1 parent 8c3ca01 commit ea4d746
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion algo_hs.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func newHS(alg Algorithm, key []byte) (*HSAlg, error) {
hash: hash,
key: key,
hashPool: &sync.Pool{
New: func() interface{} {
New: func() any {
return hmac.New(hash.New, key)
},
},
Expand Down
4 changes: 2 additions & 2 deletions audience.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (a Audience) MarshalJSON() ([]byte, error) {

// UnmarshalJSON implements json.Unmarshaler interface.
func (a *Audience) UnmarshalJSON(b []byte) error {
var v interface{}
var v any
if err := json.Unmarshal(b, &v); err != nil {
return ErrAudienceInvalidFormat
}
Expand All @@ -29,7 +29,7 @@ func (a *Audience) UnmarshalJSON(b []byte) error {
case string:
*a = Audience{v}
return nil
case []interface{}:
case []any:
aud := make(Audience, len(v))
for i := range v {
v, ok := v[i].(string)
Expand Down
4 changes: 2 additions & 2 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func NewBuilder(signer Signer, opts ...BuilderOption) *Builder {
// Build used to create and encode JWT with a provided claims.
// If claims param is of type []byte or string then it's treated as a marshaled JSON.
// In other words you can pass already marshaled claims.
func (b *Builder) Build(claims interface{}) (*Token, error) {
func (b *Builder) Build(claims any) (*Token, error) {
rawClaims, err := encodeClaims(claims)
if err != nil {
return nil, err
Expand Down Expand Up @@ -89,7 +89,7 @@ func (b *Builder) Build(claims interface{}) (*Token, error) {
return t, nil
}

func encodeClaims(claims interface{}) ([]byte, error) {
func encodeClaims(claims any) ([]byte, error) {
switch claims := claims.(type) {
case []byte:
return claims, nil
Expand Down
6 changes: 3 additions & 3 deletions build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func TestBuild(t *testing.T) {
f := func(signer Signer, verifier Verifier, claims interface{}) {
f := func(signer Signer, verifier Verifier, claims any) {
t.Helper()

token, err := NewBuilder(signer).Build(claims)
Expand Down Expand Up @@ -163,7 +163,7 @@ func TestBuildClaims(t *testing.T) {
s := mustSigner(NewSignerHS(HS256, key))
v := mustVerifier(NewVerifierHS(HS256, key))

f := func(claims interface{}, want string) {
f := func(claims any, want string) {
token, err := NewBuilder(s).Build(claims)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -208,7 +208,7 @@ func TestBuildClaims(t *testing.T) {
}

func TestBuildMalformed(t *testing.T) {
f := func(signer Signer, claims interface{}) {
f := func(signer Signer, claims any) {
t.Helper()

_, err := NewBuilder(signer).Build(claims)
Expand Down
2 changes: 1 addition & 1 deletion jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (t *Token) Claims() json.RawMessage {
}

// DecodeClaims into a given parameter.
func (t *Token) DecodeClaims(dst interface{}) error {
func (t *Token) DecodeClaims(dst any) error {
return json.Unmarshal(t.claims, dst)
}

Expand Down
2 changes: 1 addition & 1 deletion jwt_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,6 @@ func runVerifyBench(b *testing.B, builder *jwt.Builder, verifier jwt.Verifier) {
sink(dummy)
}

func sink(v interface{}) {
func sink(v any) {
fmt.Fprint(io.Discard, v)
}
2 changes: 1 addition & 1 deletion parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func Parse(raw []byte, verifier Verifier) (*Token, error) {
}

// ParseClaims decodes a token claims and verifies it's signature.
func ParseClaims(raw []byte, verifier Verifier, claims interface{}) error {
func ParseClaims(raw []byte, verifier Verifier, claims any) error {
token, err := Parse(raw, verifier)
if err != nil {
return err
Expand Down

0 comments on commit ea4d746

Please sign in to comment.