chore: lint code with golangci-lint (#1828)

* feat: add golangci-lint linting

* chore: fix linter issues

* feat: add linting into the workflow

* docs: update lint docs

* fix: cr suggestions

* fix: remove old formatting and vetting scripts

* fix: add docker make target

* fix: action go caching

* fix: depreciated actions checkout version

* fix: cr suggestion

* fix: cr suggestions

---------

Co-authored-by: Manu Gupta <manugupt1@gmail.com>
This commit is contained in:
Nicholas Wiersma
2023-02-25 06:39:17 +02:00
committed by GitHub
parent 66582eebfe
commit d932d50232
134 changed files with 596 additions and 600 deletions
+1 -1
View File
@@ -7,7 +7,7 @@ import (
"github.com/gomods/athens/pkg/paths"
)
func getModuleParams(r *http.Request, op errors.Op) (mod string, ver string, err error) {
func getModuleParams(r *http.Request, op errors.Op) (mod, ver string, err error) {
params, err := paths.GetAllParams(r)
if err != nil {
return "", "", errors.E(op, err, errors.KindBadRequest)
+2 -3
View File
@@ -15,8 +15,7 @@ import (
// a ready-to-go http handler that serves up cmd/go's download protocol.
type ProtocolHandler func(dp Protocol, lggr log.Entry, df *mode.DownloadFile) http.Handler
// HandlerOpts are the generic options
// for a ProtocolHandler
// HandlerOpts are the generic options for a ProtocolHandler.
type HandlerOpts struct {
Protocol Protocol
Logger *log.Logger
@@ -26,7 +25,7 @@ type HandlerOpts struct {
// LogEntryHandler pulls a log entry from the request context. Thanks to the
// LogEntryMiddleware, we should have a log entry stored in the context for each
// request with request-specific fields. This will grab the entry and pass it to
// the protocol handlers
// the protocol handlers.
func LogEntryHandler(ph ProtocolHandler, opts *HandlerOpts) http.Handler {
f := func(w http.ResponseWriter, r *http.Request) {
ent := log.EntryFromContext(r.Context())
+1 -1
View File
@@ -13,7 +13,7 @@ import (
// PathLatest URL.
const PathLatest = "/{module:.+}/@latest"
// LatestHandler implements GET baseURL/module/@latest
// LatestHandler implements GET baseURL/module/@latest.
func LatestHandler(dp Protocol, lggr log.Entry, df *mode.DownloadFile) http.Handler {
const op errors.Op = "download.LatestHandler"
f := func(w http.ResponseWriter, r *http.Request) {
+1 -1
View File
@@ -14,7 +14,7 @@ import (
// PathList URL.
const PathList = "/{module:.+}/@v/list"
// ListHandler implements GET baseURL/module/@v/list
// ListHandler implements GET baseURL/module/@v/list.
func ListHandler(dp Protocol, lggr log.Entry, df *mode.DownloadFile) http.Handler {
const op errors.Op = "download.ListHandler"
f := func(w http.ResponseWriter, r *http.Request) {
+3 -2
View File
@@ -4,6 +4,7 @@ import (
"encoding/base64"
"fmt"
"os"
"path/filepath"
"strings"
"github.com/gomods/athens/pkg/errors"
@@ -16,7 +17,7 @@ import (
// when a module is not found in storage.
type Mode string
// DownloadMode constants. For more information see config.dev.toml
// DownloadMode constants. For more information see config.dev.toml.
const (
Sync Mode = "sync"
Async Mode = "async"
@@ -59,7 +60,7 @@ func NewFile(m Mode, downloadURL string) (*DownloadFile, error) {
if strings.HasPrefix(string(m), "file:") {
filePath := string(m[5:])
bts, err := os.ReadFile(filePath)
bts, err := os.ReadFile(filepath.Clean(filePath))
if err != nil {
return nil, err
}
+6 -6
View File
@@ -48,7 +48,7 @@ type Opts struct {
NetworkMode string
}
// NetworkMode constants
// NetworkMode constants.
const (
Strict = "strict"
Offline = "offline"
@@ -263,12 +263,12 @@ func (p *protocol) processDownload(ctx context.Context, mod, ver string, f func(
}
return f(newVer)
case mode.Async:
go p.stasher.Stash(ctx, mod, ver)
go func() { _, _ = p.stasher.Stash(ctx, mod, ver) }()
return errors.E(op, "async: module not found", errors.KindNotFound)
case mode.Redirect:
return errors.E(op, "redirect", errors.KindRedirect)
case mode.AsyncRedirect:
go p.stasher.Stash(ctx, mod, ver)
go func() { _, _ = p.stasher.Stash(ctx, mod, ver) }()
return errors.E(op, "async_redirect: module not found", errors.KindRedirect)
case mode.None:
return errors.E(op, "none", errors.KindNotFound)
@@ -276,7 +276,7 @@ func (p *protocol) processDownload(ctx context.Context, mod, ver string, f func(
return nil
}
// union concatenates two version lists and removes duplicates
// union concatenates two version lists and removes duplicates.
func union(list1, list2 []string) []string {
if list1 == nil {
list1 = []string{}
@@ -284,10 +284,10 @@ func union(list1, list2 []string) []string {
if list2 == nil {
list2 = []string{}
}
list := append(list1, list2...)
list1 = append(list1, list2...)
unique := []string{}
m := make(map[string]struct{})
for _, v := range list {
for _, v := range list1 {
if _, ok := m[v]; !ok {
unique = append(unique, v)
m[v] = struct{}{}
+2 -2
View File
@@ -11,7 +11,7 @@ import (
// PathVersionInfo URL.
const PathVersionInfo = "/{module:.+}/@v/{version}.info"
// InfoHandler implements GET baseURL/module/@v/version.info
// InfoHandler implements GET baseURL/module/@v/version.info.
func InfoHandler(dp Protocol, lggr log.Entry, df *mode.DownloadFile) http.Handler {
const op errors.Op = "download.InfoHandler"
f := func(w http.ResponseWriter, r *http.Request) {
@@ -38,7 +38,7 @@ func InfoHandler(dp Protocol, lggr log.Entry, df *mode.DownloadFile) http.Handle
w.WriteHeader(errors.Kind(err))
}
w.Write(info)
_, _ = w.Write(info)
}
return http.HandlerFunc(f)
}
+2 -2
View File
@@ -11,7 +11,7 @@ import (
// PathVersionModule URL.
const PathVersionModule = "/{module:.+}/@v/{version}.mod"
// ModuleHandler implements GET baseURL/module/@v/version.mod
// ModuleHandler implements GET baseURL/module/@v/version.mod.
func ModuleHandler(dp Protocol, lggr log.Entry, df *mode.DownloadFile) http.Handler {
const op errors.Op = "download.VersionModuleHandler"
f := func(w http.ResponseWriter, r *http.Request) {
@@ -42,7 +42,7 @@ func ModuleHandler(dp Protocol, lggr log.Entry, df *mode.DownloadFile) http.Hand
return
}
w.Write(modBts)
_, _ = w.Write(modBts)
}
return http.HandlerFunc(f)
}
+2 -2
View File
@@ -13,7 +13,7 @@ import (
// PathVersionZip URL.
const PathVersionZip = "/{module:.+}/@v/{version}.zip"
// ZipHandler implements GET baseURL/module/@v/version.zip
// ZipHandler implements GET baseURL/module/@v/version.zip.
func ZipHandler(dp Protocol, lggr log.Entry, df *mode.DownloadFile) http.Handler {
const op errors.Op = "download.ZipHandler"
f := func(w http.ResponseWriter, r *http.Request) {
@@ -41,7 +41,7 @@ func ZipHandler(dp Protocol, lggr log.Entry, df *mode.DownloadFile) http.Handler
w.WriteHeader(errors.Kind(err))
return
}
defer zip.Close()
defer func() { _ = zip.Close() }()
w.Header().Set("Content-Type", "application/zip")
size := zip.Size()