mirror of https://github.com/golang-jwt/jwt.git
Add golangci-lint (#279)
* Add golangci-lint-action * Upgrading CodeQL to v2 * Fixed linting errors --------- Co-authored-by: Christian Banse <oxisto@aybaze.com>
This commit is contained in:
parent
843e9bfe4d
commit
15f96b0627
|
@ -8,24 +8,12 @@ on:
|
||||||
types: [opened, synchronize, reopened]
|
types: [opened, synchronize, reopened]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
check:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
- uses: reviewdog/action-staticcheck@v1
|
|
||||||
with:
|
|
||||||
github_token: ${{ secrets.github_token }}
|
|
||||||
reporter: github-pr-review
|
|
||||||
filter_mode: nofilter
|
|
||||||
fail_on_error: true
|
|
||||||
|
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
go: ["1.18", "1.19", "1.20"]
|
go: ["1.18.x", "1.19.x", "1.20.x"]
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
|
@ -13,12 +13,10 @@ name: "CodeQL"
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ main ]
|
branches: [main]
|
||||||
# pull_request:
|
pull_request:
|
||||||
# The branches below must be a subset of the branches above
|
|
||||||
# branches: [ main ]
|
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '31 10 * * 5'
|
- cron: "31 10 * * 5"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
analyze:
|
analyze:
|
||||||
|
@ -32,40 +30,40 @@ jobs:
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
language: [ 'go' ]
|
language: ["go"]
|
||||||
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
|
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
|
||||||
# Learn more:
|
# Learn more:
|
||||||
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
|
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
# Initializes the CodeQL tools for scanning.
|
# Initializes the CodeQL tools for scanning.
|
||||||
- name: Initialize CodeQL
|
- name: Initialize CodeQL
|
||||||
uses: github/codeql-action/init@v1
|
uses: github/codeql-action/init@v2
|
||||||
with:
|
with:
|
||||||
languages: ${{ matrix.language }}
|
languages: ${{ matrix.language }}
|
||||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||||
# By default, queries listed here will override any specified in a config file.
|
# By default, queries listed here will override any specified in a config file.
|
||||||
# Prefix the list here with "+" to use these queries and those in the config file.
|
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||||
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
||||||
|
|
||||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||||
# If this step fails, then you should remove it and run the build manually (see below)
|
# If this step fails, then you should remove it and run the build manually (see below)
|
||||||
- name: Autobuild
|
- name: Autobuild
|
||||||
uses: github/codeql-action/autobuild@v1
|
uses: github/codeql-action/autobuild@v2
|
||||||
|
|
||||||
# ℹ️ Command-line programs to run using the OS shell.
|
# ℹ️ Command-line programs to run using the OS shell.
|
||||||
# 📚 https://git.io/JvXDl
|
# 📚 https://git.io/JvXDl
|
||||||
|
|
||||||
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
||||||
# and modify them (or add more) to build your code if your project
|
# and modify them (or add more) to build your code if your project
|
||||||
# uses a compiled language
|
# uses a compiled language
|
||||||
|
|
||||||
#- run: |
|
#- run: |
|
||||||
# make bootstrap
|
# make bootstrap
|
||||||
# make release
|
# make release
|
||||||
|
|
||||||
- name: Perform CodeQL Analysis
|
- name: Perform CodeQL Analysis
|
||||||
uses: github/codeql-action/analyze@v1
|
uses: github/codeql-action/analyze@v2
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
name: golangci
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
pull_request:
|
||||||
|
jobs:
|
||||||
|
golangci:
|
||||||
|
name: lint
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Setup Go
|
||||||
|
uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: "1.20.x"
|
||||||
|
check-latest: true
|
||||||
|
cache: true
|
||||||
|
- name: golangci-lint
|
||||||
|
uses: golangci/golangci-lint-action@v3
|
||||||
|
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
|
||||||
|
|
||||||
|
# Optional: working directory, useful for monorepos
|
||||||
|
# working-directory: somedir
|
||||||
|
|
||||||
|
# Optional: golangci-lint command line arguments.
|
||||||
|
# args: --issues-exit-code=0
|
||||||
|
|
||||||
|
# Optional: show only new issues if it's a pull request. The default value is `false`.
|
||||||
|
# only-new-issues: true
|
||||||
|
|
||||||
|
# Optional: if set to true then the all caching functionality will be complete disabled,
|
||||||
|
# takes precedence over all other caching options.
|
||||||
|
# skip-cache: true
|
||||||
|
|
||||||
|
# Optional: if set to true then the action don't cache or restore ~/go/pkg.
|
||||||
|
# skip-pkg-cache: true
|
||||||
|
|
||||||
|
# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
|
||||||
|
# skip-build-cache: true
|
|
@ -38,7 +38,7 @@ func ExampleNewWithClaims_customClaimsType() {
|
||||||
jwt.RegisteredClaims
|
jwt.RegisteredClaims
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the claims
|
// Create claims with multiple fields populated
|
||||||
claims := MyCustomClaims{
|
claims := MyCustomClaims{
|
||||||
"bar",
|
"bar",
|
||||||
jwt.RegisteredClaims{
|
jwt.RegisteredClaims{
|
||||||
|
@ -53,6 +53,8 @@ func ExampleNewWithClaims_customClaimsType() {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Printf("foo: %v\n", claims.Foo)
|
||||||
|
|
||||||
// Create claims while leaving out some of the optional fields
|
// Create claims while leaving out some of the optional fields
|
||||||
claims = MyCustomClaims{
|
claims = MyCustomClaims{
|
||||||
"bar",
|
"bar",
|
||||||
|
@ -67,7 +69,8 @@ func ExampleNewWithClaims_customClaimsType() {
|
||||||
ss, err := token.SignedString(mySigningKey)
|
ss, err := token.SignedString(mySigningKey)
|
||||||
fmt.Printf("%v %v", ss, err)
|
fmt.Printf("%v %v", ss, err)
|
||||||
|
|
||||||
//Output: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmb28iOiJiYXIiLCJpc3MiOiJ0ZXN0IiwiZXhwIjoxNTE2MjM5MDIyfQ.xVuY2FZ_MRXMIEgVQ7J-TFtaucVFRXUzHm9LmV41goM <nil>
|
//Output: foo: bar
|
||||||
|
//eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmb28iOiJiYXIiLCJpc3MiOiJ0ZXN0IiwiZXhwIjoxNTE2MjM5MDIyfQ.xVuY2FZ_MRXMIEgVQ7J-TFtaucVFRXUzHm9LmV41goM <nil>
|
||||||
}
|
}
|
||||||
|
|
||||||
// Example creating a token using a custom claims type. The RegisteredClaims is embedded
|
// Example creating a token using a custom claims type. The RegisteredClaims is embedded
|
||||||
|
|
|
@ -94,7 +94,8 @@ func Example_getTokenViaHTTP() {
|
||||||
|
|
||||||
// Read the token out of the response body
|
// Read the token out of the response body
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
io.Copy(buf, res.Body)
|
_, err = io.Copy(buf, res.Body)
|
||||||
|
fatal(err)
|
||||||
res.Body.Close()
|
res.Body.Close()
|
||||||
tokenString := strings.TrimSpace(buf.String())
|
tokenString := strings.TrimSpace(buf.String())
|
||||||
|
|
||||||
|
@ -129,7 +130,8 @@ func Example_useTokenViaHTTP() {
|
||||||
|
|
||||||
// Read the response body
|
// Read the response body
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
io.Copy(buf, res.Body)
|
_, err = io.Copy(buf, res.Body)
|
||||||
|
fatal(err)
|
||||||
res.Body.Close()
|
res.Body.Close()
|
||||||
fmt.Println(buf.String())
|
fmt.Println(buf.String())
|
||||||
|
|
||||||
|
|
|
@ -38,8 +38,8 @@ func (e HeaderExtractor) ExtractToken(req *http.Request) (string, error) {
|
||||||
type ArgumentExtractor []string
|
type ArgumentExtractor []string
|
||||||
|
|
||||||
func (e ArgumentExtractor) ExtractToken(req *http.Request) (string, error) {
|
func (e ArgumentExtractor) ExtractToken(req *http.Request) (string, error) {
|
||||||
// Make sure form is parsed
|
// Make sure form is parsed. We are explicitly ignoring errors at this point
|
||||||
req.ParseMultipartForm(10e6)
|
_ = req.ParseMultipartForm(10e6)
|
||||||
|
|
||||||
// loop over arg names and return the first one that contains data
|
// loop over arg names and return the first one that contains data
|
||||||
for _, arg := range e {
|
for _, arg := range e {
|
||||||
|
|
|
@ -72,7 +72,7 @@ func BenchmarkToken_SigningString(b *testing.B) {
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
t.SigningString()
|
_, _ = t.SigningString()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue