From d272f4dadc705683992e33123d0f8574c0bb8ea4 Mon Sep 17 00:00:00 2001 From: jay-dee7 Date: Mon, 28 Mar 2022 03:03:36 +0530 Subject: [PATCH 1/3] Chore: Added Github Action to auto format code on push to main Signed-off-by: jay-dee7 --- .github/workflows/auto-formatter.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .github/workflows/auto-formatter.yml diff --git a/.github/workflows/auto-formatter.yml b/.github/workflows/auto-formatter.yml new file mode 100644 index 00000000..c411b583 --- /dev/null +++ b/.github/workflows/auto-formatter.yml @@ -0,0 +1,21 @@ +name: gofumpt + +on: + push: + branches: [main] + +jobs: + prettier: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + ref: ${{ github.head_ref }} + fetch-depth: 0 + + - name: Auto Format code + uses: iamnotaturtle/auto-gofmt@v2.0.0 + with: + only_changed: true From 1697222a720e34c21444efab82dce83794d9e7c6 Mon Sep 17 00:00:00 2001 From: Mike Fridman Date: Fri, 27 May 2022 19:14:46 -0400 Subject: [PATCH 2/3] Add Go code formatting --- .github/workflows/auto-formatter.yml | 21 --------------------- .github/workflows/build.yml | 7 +++++++ 2 files changed, 7 insertions(+), 21 deletions(-) delete mode 100644 .github/workflows/auto-formatter.yml diff --git a/.github/workflows/auto-formatter.yml b/.github/workflows/auto-formatter.yml deleted file mode 100644 index c411b583..00000000 --- a/.github/workflows/auto-formatter.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: gofumpt - -on: - push: - branches: [main] - -jobs: - prettier: - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v2 - with: - ref: ${{ github.head_ref }} - fetch-depth: 0 - - - name: Auto Format code - uses: iamnotaturtle/auto-gofmt@v2.0.0 - with: - only_changed: true diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3fce11e6..984ab2da 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -33,6 +33,13 @@ jobs: uses: actions/setup-go@v3 with: go-version: "${{ matrix.go }}" + - name: Check Go code formatting + run: | + if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then + gofmt -s -l . + echo "Please format Go code by running: go fmt ./..." + exit 1 + fi - name: Build run: | go vet ./... From de7268f1f8e8300d9db89ac70de8c4bc2138fcfd Mon Sep 17 00:00:00 2001 From: Mike Fridman Date: Fri, 27 May 2022 19:14:55 -0400 Subject: [PATCH 3/3] Format Go code go fmt ./... --- map_claims_test.go | 4 ++-- rsa_pss.go | 1 + rsa_pss_test.go | 1 + token.go | 1 - token_test.go | 8 ++++---- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/map_claims_test.go b/map_claims_test.go index b8b9eb74..361c49d2 100644 --- a/map_claims_test.go +++ b/map_claims_test.go @@ -110,13 +110,13 @@ func TestMapClaimsVerifyExpiresAtExpire(t *testing.T) { t.Fatalf("Failed to verify claims, wanted: %v got %v", want, got) } - got = mapClaims.VerifyExpiresAt(exp + 1, true) + got = mapClaims.VerifyExpiresAt(exp+1, true) if want != got { t.Fatalf("Failed to verify claims, wanted: %v got %v", want, got) } want = true - got = mapClaims.VerifyExpiresAt(exp - 1, true) + got = mapClaims.VerifyExpiresAt(exp-1, true) if want != got { t.Fatalf("Failed to verify claims, wanted: %v got %v", want, got) } diff --git a/rsa_pss.go b/rsa_pss.go index 5a8502fe..4fd6f9e6 100644 --- a/rsa_pss.go +++ b/rsa_pss.go @@ -1,3 +1,4 @@ +//go:build go1.4 // +build go1.4 package jwt diff --git a/rsa_pss_test.go b/rsa_pss_test.go index 5b895da5..91a65cf4 100644 --- a/rsa_pss_test.go +++ b/rsa_pss_test.go @@ -1,3 +1,4 @@ +//go:build go1.4 // +build go1.4 package jwt_test diff --git a/token.go b/token.go index 09b4cde5..3cb0f3f0 100644 --- a/token.go +++ b/token.go @@ -7,7 +7,6 @@ import ( "time" ) - // DecodePaddingAllowed will switch the codec used for decoding JWTs respectively. Note that the JWS RFC7515 // states that the tokens will utilize a Base64url encoding with no padding. Unfortunately, some implementations // of JWT are producing non-standard tokens, and thus require support for decoding. Note that this is a global diff --git a/token_test.go b/token_test.go index 7944b51e..e0d740a9 100644 --- a/token_test.go +++ b/token_test.go @@ -34,7 +34,7 @@ func TestToken_SigningString(t1 *testing.T) { Signature: "", Valid: false, }, - want: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30", + want: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30", wantErr: false, }, } @@ -62,17 +62,17 @@ func TestToken_SigningString(t1 *testing.T) { func BenchmarkToken_SigningString(b *testing.B) { t := &jwt.Token{ - Method: jwt.SigningMethodHS256, + Method: jwt.SigningMethodHS256, Header: map[string]interface{}{ "typ": "JWT", "alg": jwt.SigningMethodHS256.Alg(), }, - Claims: jwt.StandardClaims{}, + Claims: jwt.StandardClaims{}, } b.Run("BenchmarkToken_SigningString", func(b *testing.B) { b.ResetTimer() b.ReportAllocs() - for i := 0; i