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
7 changes: 2 additions & 5 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@ jobs:
uses: actions/setup-go@v7
with:
go-version-file: "go.mod"
- name: Setup golangci-lint
uses: golangci/golangci-lint-action@v9
with:
version: v2.12
args: --verbose
- name: Run lint
run: make install-tools lint
test:
strategy:
matrix:
Expand Down
123 changes: 93 additions & 30 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,89 @@
version: "2"
output:
sort-order:
- file
linters:
default: none
enable:
- bidichk
- bodyclose
- dogsled
- dupl
- depguard
- errcheck
- exhaustive
- gochecknoinits
- goconst
- forbidigo
- gocheckcompilerdirectives
- gocritic
- gocyclo
- goprintffuncname
- gosec
- govet
- ineffassign
- lll
- misspell
- mirror
- modernize
- nakedret
- noctx
- nilnil
- nolintlint
- rowserrcheck
- perfsprint
- revive
- staticcheck
- testifylint
- unconvert
- unparam
- unused
- whitespace
- usestdlibvars
- usetesting
- wastedassign
settings:
depguard:
rules:
main:
deny:
- pkg: io/ioutil
desc: use os or io instead
- pkg: golang.org/x/exp
desc: it's experimental and unreliable
- pkg: github.com/pkg/errors
desc: use builtin errors package instead
nolintlint:
allow-unused: false
require-explanation: true
require-specific: true
gocritic:
enabled-checks:
- equalFold
disabled-checks: []
revive:
severity: error
rules:
- name: blank-imports
- name: constant-logical-expr
- name: context-as-argument
- name: context-keys-type
- name: dot-imports
- name: empty-lines
- name: error-return
- name: error-strings
- name: exported
- name: identical-branches
- name: if-return
- name: increment-decrement
- name: modifies-value-receiver
- name: package-comments
- name: redefines-builtin-id
- name: superfluous-else
- name: time-naming
- name: unexported-return
- name: var-declaration
- name: var-naming
disabled: true
staticcheck:
checks:
- all
testifylint: {}
usetesting:
os-temp-dir: true
perfsprint:
concat-loop: false
govet:
enable:
- nilness
- unusedwrite
exclusions:
generated: lax
presets:
Expand All @@ -35,27 +93,32 @@ linters:
- std-error-handling
rules:
- linters:
- bodyclose
- errcheck
- staticcheck
- unparam
path: authenticator_test.go
- linters:
- lll
path: parser_test.go
- linters:
- lll
path: signatureheader_test.go
paths:
- third_party$
- builtin$
- examples$
path: _test\.go
issues:
max-issues-per-linter: 0
max-same-issues: 0
formatters:
enable:
- gci
- gofmt
- gofumpt
- goimports
- golines
settings:
gci:
custom-order: true
sections:
- standard
- prefix(github.com/gin-contrib/httpsign)
- default
gofumpt:
extra:
group-params: true
clothe-returns: true
balance-calls: true
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
run:
timeout: 10m
40 changes: 40 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
GO ?= go
TOOLS_MOD := -modfile=go.tools.mod

## lint: run golangci-lint to check for issues
lint:
$(GO) tool $(TOOLS_MOD) golangci-lint run

## fmt: format go files using golangci-lint
fmt:
$(GO) tool $(TOOLS_MOD) golangci-lint fmt

## test: run tests
test:
$(GO) test -v -cover -coverprofile=coverage.txt ./... && echo "\n==>\033[32m Ok\033[m\n" || exit 1

## coverage: view test coverage in browser
coverage: test
$(GO) tool cover -html=coverage.txt

## mod-download: download go module dependencies
mod-download:
$(GO) mod download

## mod-tidy: tidy go module dependencies
mod-tidy:
$(GO) mod tidy

## mod-verify: verify go module dependencies
mod-verify:
$(GO) mod verify

## install-tools: download tool dependencies
install-tools:
$(GO) mod download $(TOOLS_MOD)

## help: print this help message
help:
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'

.PHONY: lint fmt test coverage mod-download mod-tidy mod-verify install-tools help
8 changes: 5 additions & 3 deletions authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"

"github.com/gin-contrib/httpsign/validator"

"github.com/gin-gonic/gin"
)

Expand Down Expand Up @@ -117,13 +118,14 @@ func (a *Authenticator) Authenticated() gin.HandlerFunc {
func (a *Authenticator) isValidHeader(headers []string) bool {
m := len(headers)
for _, h := range a.headers {
i := 0
for i = 0; i < m; i++ {
found := false
for i := range m {
if h == headers[i] {
found = true
break
}
}
if i == m {
if !found {
return false
}
}
Expand Down
Loading
Loading