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:
@ -43,7 +43,6 @@ linters: # All available linters list: <https://golangci-lint.run/usage/linters/
|
|||||||
enable:
|
enable:
|
||||||
- asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers
|
- asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers
|
||||||
- bidichk # Checks for dangerous unicode character sequences
|
- 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
|
- 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())
|
- dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f())
|
||||||
- dupl # Tool for code clone detection
|
- 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
|
- typecheck # Like the front-end of a Go compiler, parses and type-checks Go code
|
||||||
- unconvert # Remove unnecessary type conversions
|
- unconvert # Remove unnecessary type conversions
|
||||||
- unused # Checks Go code for unused constants, variables, functions and types
|
- 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
|
- whitespace # Tool for detection of leading and trailing whitespace
|
||||||
- wsl # Whitespace Linter - Forces you to use empty lines!
|
- wsl # Whitespace Linter - Forces you to use empty lines!
|
||||||
|
|
||||||
|
@ -3,11 +3,12 @@ package checkers_test
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
"github.com/tarampampam/error-pages/internal/checkers"
|
"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"))
|
assert.Equal(t, "HealthChecker/internal", req.Header.Get("User-Agent"))
|
||||||
|
|
||||||
return &http.Response{
|
return &http.Response{
|
||||||
Body: ioutil.NopCloser(bytes.NewReader([]byte{})),
|
Body: io.NopCloser(bytes.NewReader([]byte{})),
|
||||||
StatusCode: http.StatusOK,
|
StatusCode: http.StatusOK,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
@ -35,7 +36,7 @@ func TestHealthChecker_CheckSuccess(t *testing.T) {
|
|||||||
func TestHealthChecker_CheckFail(t *testing.T) {
|
func TestHealthChecker_CheckFail(t *testing.T) {
|
||||||
var httpMock httpClientFunc = func(req *http.Request) (*http.Response, error) {
|
var httpMock httpClientFunc = func(req *http.Request) (*http.Response, error) {
|
||||||
return &http.Response{
|
return &http.Response{
|
||||||
Body: ioutil.NopCloser(bytes.NewReader([]byte{})),
|
Body: io.NopCloser(bytes.NewReader([]byte{})),
|
||||||
StatusCode: http.StatusBadGateway,
|
StatusCode: http.StatusBadGateway,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
|
|
||||||
"github.com/tarampampam/error-pages/internal/env"
|
"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)
|
// flag was NOT defined using CLI (flags should have maximal priority)
|
||||||
if !flag.Changed && flag.Name == portFlagName {
|
if !flag.Changed && flag.Name == portFlagName {
|
||||||
if envPort, exists := env.ListenPort.Lookup(); exists && envPort != "" {
|
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)
|
port = uint16(p)
|
||||||
} else {
|
} else {
|
||||||
lastErr = fmt.Errorf("wrong TCP port environment variable [%s] value", envPort)
|
lastErr = fmt.Errorf("wrong TCP port environment variable [%s] value", envPort)
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
|
|
||||||
"github.com/tarampampam/error-pages/internal/env"
|
"github.com/tarampampam/error-pages/internal/env"
|
||||||
"github.com/tarampampam/error-pages/internal/options"
|
"github.com/tarampampam/error-pages/internal/options"
|
||||||
)
|
)
|
||||||
@ -118,7 +119,7 @@ func (f *flags) OverrideUsingEnv(flagSet *pflag.FlagSet) (lastErr error) { //nol
|
|||||||
|
|
||||||
case portFlagName:
|
case portFlagName:
|
||||||
if envVar, exists := env.ListenPort.Lookup(); exists {
|
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)
|
f.Listen.Port = uint16(p)
|
||||||
} else {
|
} else {
|
||||||
lastErr = fmt.Errorf("wrong TCP port environment variable [%s] value", envVar)
|
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:
|
case defaultHTTPCodeFlagName:
|
||||||
if envVar, exists := env.DefaultHTTPCode.Lookup(); exists {
|
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)
|
f.defaultHTTPCode = uint16(code)
|
||||||
} else {
|
} else {
|
||||||
lastErr = fmt.Errorf("wrong default HTTP response code environment variable [%s] value", envVar)
|
lastErr = fmt.Errorf("wrong default HTTP response code environment variable [%s] value", envVar)
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"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) Content() []byte { return t.content }
|
||||||
|
|
||||||
func (t *Template) loadContentFromFile(filePath string) (err error) {
|
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)
|
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.
|
// FromYamlFile creates new Config instance using YAML file.
|
||||||
func FromYamlFile(filepath string) (*Config, error) {
|
func FromYamlFile(filepath string) (*Config, error) {
|
||||||
bytes, err := ioutil.ReadFile(filepath)
|
bytes, err := os.ReadFile(filepath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "cannot read configuration file")
|
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}
|
f := format{b[0:idx], 0}
|
||||||
|
|
||||||
if len(b) > idx+3 {
|
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)
|
f.weight = float32(weight)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user