mirror of
https://github.com/tarampampam/error-pages.git
synced 2024-08-30 18:22:40 +00:00
golangci-lint issues fixed
This commit is contained in:
parent
8e21be0340
commit
cf7c526d4f
.golangci.yml
internal
@ -43,7 +43,6 @@ linters: # All available linters list: <https://golangci-lint.run/usage/linters/
|
||||
enable:
|
||||
- asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers
|
||||
- bidichk # Checks for dangerous unicode character sequences
|
||||
- deadcode # Finds unused code
|
||||
- depguard # Go linter that checks if package imports are in a list of acceptable packages
|
||||
- dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f())
|
||||
- dupl # Tool for code clone detection
|
||||
@ -78,7 +77,6 @@ linters: # All available linters list: <https://golangci-lint.run/usage/linters/
|
||||
- typecheck # Like the front-end of a Go compiler, parses and type-checks Go code
|
||||
- unconvert # Remove unnecessary type conversions
|
||||
- unused # Checks Go code for unused constants, variables, functions and types
|
||||
- varcheck # Finds unused global variables and constants
|
||||
- whitespace # Tool for detection of leading and trailing whitespace
|
||||
- wsl # Whitespace Linter - Forces you to use empty lines!
|
||||
|
||||
|
@ -3,11 +3,12 @@ package checkers_test
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/tarampampam/error-pages/internal/checkers"
|
||||
)
|
||||
|
||||
@ -22,7 +23,7 @@ func TestHealthChecker_CheckSuccess(t *testing.T) {
|
||||
assert.Equal(t, "HealthChecker/internal", req.Header.Get("User-Agent"))
|
||||
|
||||
return &http.Response{
|
||||
Body: ioutil.NopCloser(bytes.NewReader([]byte{})),
|
||||
Body: io.NopCloser(bytes.NewReader([]byte{})),
|
||||
StatusCode: http.StatusOK,
|
||||
}, nil
|
||||
}
|
||||
@ -35,7 +36,7 @@ func TestHealthChecker_CheckSuccess(t *testing.T) {
|
||||
func TestHealthChecker_CheckFail(t *testing.T) {
|
||||
var httpMock httpClientFunc = func(req *http.Request) (*http.Response, error) {
|
||||
return &http.Response{
|
||||
Body: ioutil.NopCloser(bytes.NewReader([]byte{})),
|
||||
Body: io.NopCloser(bytes.NewReader([]byte{})),
|
||||
StatusCode: http.StatusBadGateway,
|
||||
}, nil
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/pflag"
|
||||
|
||||
"github.com/tarampampam/error-pages/internal/env"
|
||||
)
|
||||
|
||||
@ -29,7 +30,7 @@ func NewCommand(checker checker) *cobra.Command {
|
||||
// flag was NOT defined using CLI (flags should have maximal priority)
|
||||
if !flag.Changed && flag.Name == portFlagName {
|
||||
if envPort, exists := env.ListenPort.Lookup(); exists && envPort != "" {
|
||||
if p, err := strconv.ParseUint(envPort, 10, 16); err == nil { //nolint:gomnd
|
||||
if p, err := strconv.ParseUint(envPort, 10, 16); err == nil {
|
||||
port = uint16(p)
|
||||
} else {
|
||||
lastErr = fmt.Errorf("wrong TCP port environment variable [%s] value", envPort)
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
|
||||
"github.com/tarampampam/error-pages/internal/env"
|
||||
"github.com/tarampampam/error-pages/internal/options"
|
||||
)
|
||||
@ -118,7 +119,7 @@ func (f *flags) OverrideUsingEnv(flagSet *pflag.FlagSet) (lastErr error) { //nol
|
||||
|
||||
case portFlagName:
|
||||
if envVar, exists := env.ListenPort.Lookup(); exists {
|
||||
if p, err := strconv.ParseUint(envVar, 10, 16); err == nil { //nolint:gomnd
|
||||
if p, err := strconv.ParseUint(envVar, 10, 16); err == nil {
|
||||
f.Listen.Port = uint16(p)
|
||||
} else {
|
||||
lastErr = fmt.Errorf("wrong TCP port environment variable [%s] value", envVar)
|
||||
@ -137,7 +138,7 @@ func (f *flags) OverrideUsingEnv(flagSet *pflag.FlagSet) (lastErr error) { //nol
|
||||
|
||||
case defaultHTTPCodeFlagName:
|
||||
if envVar, exists := env.DefaultHTTPCode.Lookup(); exists {
|
||||
if code, err := strconv.ParseUint(envVar, 10, 16); err == nil { //nolint:gomnd
|
||||
if code, err := strconv.ParseUint(envVar, 10, 16); err == nil {
|
||||
f.defaultHTTPCode = uint16(code)
|
||||
} else {
|
||||
lastErr = fmt.Errorf("wrong default HTTP response code environment variable [%s] value", envVar)
|
||||
|
@ -1,7 +1,6 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
@ -68,7 +67,7 @@ func (t Template) Name() string { return t.name }
|
||||
func (t Template) Content() []byte { return t.content }
|
||||
|
||||
func (t *Template) loadContentFromFile(filePath string) (err error) {
|
||||
if t.content, err = ioutil.ReadFile(filePath); err != nil {
|
||||
if t.content, err = os.ReadFile(filePath); err != nil {
|
||||
return errors.Wrap(err, "cannot load content for the template "+t.Name()+" from file "+filePath)
|
||||
}
|
||||
|
||||
@ -236,7 +235,7 @@ func FromYaml(in []byte) (_ *Config, err error) {
|
||||
|
||||
// FromYamlFile creates new Config instance using YAML file.
|
||||
func FromYamlFile(filepath string) (*Config, error) {
|
||||
bytes, err := ioutil.ReadFile(filepath)
|
||||
bytes, err := os.ReadFile(filepath)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "cannot read configuration file")
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ func ClientWantFormat(ctx *fasthttp.RequestCtx) ContentType {
|
||||
f := format{b[0:idx], 0}
|
||||
|
||||
if len(b) > idx+3 {
|
||||
if weight, err := strconv.ParseFloat(string(b[idx+3:]), 32); err == nil { //nolint:gomnd
|
||||
if weight, err := strconv.ParseFloat(string(b[idx+3:]), 32); err == nil {
|
||||
f.weight = float32(weight)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user