Skip to content

Commit

Permalink
golangci-lint issues fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
tarampampam committed Nov 1, 2022
1 parent 8e21be0 commit cf7c526
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
2 changes: 0 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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!

Expand Down
7 changes: 4 additions & 3 deletions internal/checkers/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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
}
Expand All @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion internal/cli/healthcheck/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/spf13/cobra"
"github.com/spf13/pflag"

"github.com/tarampampam/error-pages/internal/env"
)

Expand All @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions internal/cli/serve/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"

"github.com/spf13/pflag"

"github.com/tarampampam/error-pages/internal/env"
"github.com/tarampampam/error-pages/internal/options"
)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions internal/config/config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package config

import (
"io/ioutil"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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")
}
Expand Down
2 changes: 1 addition & 1 deletion internal/http/core/formats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit cf7c526

Please sign in to comment.