🚨 Removed linter warnings

This commit is contained in:
Maxim Lebedev 2021-10-05 01:06:35 +05:00
parent 650a1ec975
commit e2961e6642
Signed by: toby3d
GPG Key ID: 1F14E25B7C119FC5
6 changed files with 31 additions and 28 deletions

View File

@ -5,9 +5,14 @@ linters-settings:
lll:
tab-width: 8
gci:
local-prefixes: source.toby3d.me/
local-prefixes: source.toby3d.me
goimports:
local-prefixes: source.toby3d.me/
local-prefixes: source.toby3d.me
linters:
enable-all: true
issues:
exclude-rules:
- source: "^//go:generate "
linters:
- lll
fix: true

View File

@ -30,8 +30,7 @@ type (
)
// HeaderXCSRFToken describes the name of the header with the CSRF token.
//nolint: gosec
const HeaderXCSRFToken string = "X-CSRF-Token"
const HeaderXCSRFToken string = "X-CSRF-Token" //nolint: gosec
var (
ErrMissingFormToken = errors.New("missing csrf token in the form parameter")
@ -39,23 +38,23 @@ var (
)
// DefaultCSRFConfig contains the default CSRF middleware configuration.
//nolint: exhaustivestruct, gochecknoglobals, gomnd
//nolint: gochecknoglobals, gomnd
var DefaultCSRFConfig = CSRFConfig{
ContextKey: "csrf",
CookieHTTPOnly: false,
CookieMaxAge: 24 * time.Hour,
CookieName: "_csrf",
CookieSameSite: http.CookieSameSiteDefaultMode,
CookieSecure: false,
Skipper: DefaultSkipper,
TokenLength: 32,
CookieMaxAge: 24 * time.Hour,
CookieSameSite: http.CookieSameSiteDefaultMode,
ContextKey: "csrf",
CookieDomain: "",
CookieName: "_csrf",
CookiePath: "",
TokenLookup: "header:" + HeaderXCSRFToken,
TokenLength: 32,
CookieSecure: false,
CookieHTTPOnly: false,
}
func CSRF() Interceptor {
cfg := DefaultCSRFConfig
return CSRFWithConfig(cfg)
return CSRFWithConfig(DefaultCSRFConfig)
}
//nolint: funlen, cyclop
@ -130,7 +129,7 @@ func CSRFWithConfig(config CSRFConfig) Interceptor {
}
}
// Set CSRF cookie
// NOTE(toby3d): set CSRF cookie
cookie := http.AcquireCookie()
defer http.ReleaseCookie(cookie)
@ -172,12 +171,11 @@ func csrfTokenFromHeader(header string) csrfTokenExtractor {
func csrfTokenFromForm(param string) csrfTokenExtractor {
return func(ctx *http.RequestCtx) ([]byte, error) {
token := ctx.FormValue(param)
if token == nil {
return nil, ErrMissingFormToken
if token := ctx.FormValue(param); token != nil {
return token, nil
}
return token, nil
return nil, ErrMissingFormToken
}
}

View File

@ -3,13 +3,10 @@ package middleware
import http "github.com/valyala/fasthttp"
type (
Chain []Interceptor
Interceptor func(*http.RequestCtx, http.RequestHandler)
Chain []Interceptor
Interceptor func(*http.RequestCtx, http.RequestHandler)
RequestHandler http.RequestHandler
Skipper func(*http.RequestCtx) bool
Skipper func(*http.RequestCtx) bool
)
// DefaultSkipper is the default skipper, which always returns false.

View File

@ -15,6 +15,7 @@ import (
)
type (
//nolint: tagliatelle
Response struct {
DisplayName string `json:"display_name"`
Avatar string `json:"avatar"`
@ -62,5 +63,6 @@ func (repo *mastodonProfileRepository) Get(ctx context.Context, token oauth2.Tok
Name: result.DisplayName,
URL: result.URL,
Photo: result.Avatar,
Email: "",
}, nil
}

View File

@ -34,6 +34,7 @@ func (r *Random) String(length int, charsets ...string) string {
b := make([]byte, length)
for i := range b {
//nolint: gosec
b[i] = charset[rand.Int()%len(charset)]
}

View File

@ -31,10 +31,10 @@ func TestServe(tb testing.TB, handler http.RequestHandler) (*http.Client, *http.
client := &http.Client{
TLSConfig: &tls.Config{
InsecureSkipVerify: true,
InsecureSkipVerify: true, //nolint: gosec
},
Dial: func(addr string) (net.Conn, error) {
return ln.Dial()
return ln.Dial() //nolint: wrapcheck
},
}