Skip to content
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 .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
go: ["1.21", "1.22", "1.23"]
go: ["1.22", "1.23", "1.24"]
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "1.23"
go-version: "1.24"
check-latest: true
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
uses: golangci/golangci-lint-action@v7
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: latest
Expand Down
4 changes: 3 additions & 1 deletion cmd/jwt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ func loadData(p string) ([]byte, error) {
return nil, err
}
rdr = f
defer f.Close()
if err := f.Close(); err != nil {
return nil, err
}
}
return io.ReadAll(rdr)
}
Expand Down
6 changes: 3 additions & 3 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func ExampleParseWithClaims_customClaimsType() {
if err != nil {
log.Fatal(err)
} else if claims, ok := token.Claims.(*MyCustomClaims); ok {
fmt.Println(claims.Foo, claims.RegisteredClaims.Issuer)
fmt.Println(claims.Foo, claims.Issuer)
} else {
log.Fatal("unknown claims type, cannot proceed")
}
Expand All @@ -114,7 +114,7 @@ func ExampleParseWithClaims_validationOptions() {
if err != nil {
log.Fatal(err)
} else if claims, ok := token.Claims.(*MyCustomClaims); ok {
fmt.Println(claims.Foo, claims.RegisteredClaims.Issuer)
fmt.Println(claims.Foo, claims.Issuer)
} else {
log.Fatal("unknown claims type, cannot proceed")
}
Expand Down Expand Up @@ -153,7 +153,7 @@ func ExampleParseWithClaims_customValidation() {
if err != nil {
log.Fatal(err)
} else if claims, ok := token.Claims.(*MyCustomClaims); ok {
fmt.Println(claims.Foo, claims.RegisteredClaims.Issuer)
fmt.Println(claims.Foo, claims.Issuer)
} else {
log.Fatal("unknown claims type, cannot proceed")
}
Expand Down
18 changes: 9 additions & 9 deletions http_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func Example_getTokenViaHTTP() {
// Read the token out of the response body
buf, err := io.ReadAll(res.Body)
fatal(err)
res.Body.Close()
_ = res.Body.Close()
tokenString := strings.TrimSpace(string(buf))

// Parse the token
Expand All @@ -104,7 +104,7 @@ func Example_getTokenViaHTTP() {
fatal(err)

claims := token.Claims.(*CustomClaimsExample)
fmt.Println(claims.CustomerInfo.Name)
fmt.Println(claims.Name)

// Output: test
}
Expand All @@ -126,7 +126,7 @@ func Example_useTokenViaHTTP() {
// Read the response body
buf, err := io.ReadAll(res.Body)
fatal(err)
res.Body.Close()
_ = res.Body.Close()
fmt.Printf("%s", buf)

// Output: Welcome, foo
Expand Down Expand Up @@ -156,7 +156,7 @@ func authHandler(w http.ResponseWriter, r *http.Request) {
// make sure its post
if r.Method != "POST" {
w.WriteHeader(http.StatusBadRequest)
fmt.Fprintln(w, "No POST", r.Method)
_, _ = fmt.Fprintln(w, "No POST", r.Method)
return
}

Expand All @@ -168,21 +168,21 @@ func authHandler(w http.ResponseWriter, r *http.Request) {
// check values
if user != "test" || pass != "known" {
w.WriteHeader(http.StatusForbidden)
fmt.Fprintln(w, "Wrong info")
_, _ = fmt.Fprintln(w, "Wrong info")
return
}

tokenString, err := createToken(user)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprintln(w, "Sorry, error while Signing Token!")
_, _ = fmt.Fprintln(w, "Sorry, error while Signing Token!")
log.Printf("Token Signing error: %v\n", err)
return
}

w.Header().Set("Content-Type", "application/jwt")
w.WriteHeader(http.StatusOK)
fmt.Fprintln(w, tokenString)
_, _ = fmt.Fprintln(w, tokenString)
}

// only accessible with a valid token
Expand All @@ -197,10 +197,10 @@ func restrictedHandler(w http.ResponseWriter, r *http.Request) {
// If the token is missing or invalid, return error
if err != nil {
w.WriteHeader(http.StatusUnauthorized)
fmt.Fprintln(w, "Invalid token:", err)
_, _ = fmt.Fprintln(w, "Invalid token:", err)
return
}

// Token is valid
fmt.Fprintln(w, "Welcome,", token.Claims.(*CustomClaimsExample).Name)
_, _ = fmt.Fprintln(w, "Welcome,", token.Claims.(*CustomClaimsExample).Name)
}
2 changes: 1 addition & 1 deletion parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ func TestSetPadding(t *testing.T) {
// Parse the token
var token *jwt.Token
var err error
var opts []jwt.ParserOption = []jwt.ParserOption{jwt.WithoutClaimsValidation()}
var opts = []jwt.ParserOption{jwt.WithoutClaimsValidation()}

if data.paddedDecode {
opts = append(opts, jwt.WithPaddingAllowed())
Expand Down
2 changes: 1 addition & 1 deletion validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func NewValidator(opts ...ParserOption) *Validator {
func (v *Validator) Validate(claims Claims) error {
var (
now time.Time
errs []error = make([]error, 0, 6)
errs = make([]error, 0, 6)
err error
)

Expand Down