Enable golint linter

Use the golint linter and fix the reported problems.

[NO TESTS NEEDED]

Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
This commit is contained in:
Paul Holzinger
2021-02-11 22:28:35 +01:00
parent ef2fc90f2d
commit 69ab67bf90
18 changed files with 34 additions and 42 deletions

View File

@ -51,7 +51,6 @@ linters:
- gochecknoinits
- goconst
- gocyclo
- golint
- lll
- structcheck
- typecheck

View File

@ -243,12 +243,12 @@ func ps(cmd *cobra.Command, _ []string) error {
// responses will grow to the largest number of processes reported on, but will not thrash the gc
var responses []psReporter
for ; ; responses = responses[:0] {
if ctnrs, err := getResponses(); err != nil {
ctnrs, err := getResponses()
if err != nil {
return err
} else {
for _, r := range ctnrs {
responses = append(responses, psReporter{r})
}
}
for _, r := range ctnrs {
responses = append(responses, psReporter{r})
}
tm.Clear()

View File

@ -78,11 +78,11 @@ type ExecConfig struct {
type ExecSession struct {
// Id is the ID of the exec session.
// Named somewhat strangely to not conflict with ID().
// nolint:stylecheck
// nolint:stylecheck,golint
Id string `json:"id"`
// ContainerId is the ID of the container this exec session belongs to.
// Named somewhat strangely to not conflict with ContainerID().
// nolint:stylecheck
// nolint:stylecheck,golint
ContainerId string `json:"containerId"`
// State is the state of the exec session.

View File

@ -266,7 +266,7 @@ func (c *Container) handleRestartPolicy(ctx context.Context) (_ bool, retErr err
c.newContainerEvent(events.Restart)
// Increment restart count
c.state.RestartCount += 1
c.state.RestartCount++
logrus.Debugf("Container %s now on retry %d", c.ID(), c.state.RestartCount)
if err := c.save(); err != nil {
return false, err

View File

@ -190,7 +190,7 @@ func (c *Container) updateHealthCheckLog(hcl define.HealthCheckLog, inStartPerio
}
if !inStartPeriod {
// increment failing streak
healthCheck.FailingStreak += 1
healthCheck.FailingStreak++
// if failing streak > retries, then status to unhealthy
if healthCheck.FailingStreak >= c.HealthCheckConfig().Retries {
healthCheck.Status = define.HealthCheckUnhealthy

View File

@ -75,9 +75,8 @@ func findImageInRepotags(search imageParts, images []*Image) (*storage.Image, er
}
if rwImageCnt > 1 {
return nil, errors.Wrapf(define.ErrMultipleImages, "found multiple read/write images %s", strings.Join(keys, ","))
} else {
return nil, errors.Wrapf(define.ErrMultipleImages, "found multiple read/only images %s", strings.Join(keys, ","))
}
return nil, errors.Wrapf(define.ErrMultipleImages, "found multiple read/only images %s", strings.Join(keys, ","))
}
return candidates[0].image.image, nil
}

View File

@ -222,11 +222,11 @@ func (r *Runtime) getContainerStoreInfo() (define.ContainerStore, error) {
}
switch state {
case define.ContainerStateRunning:
running += 1
running++
case define.ContainerStatePaused:
paused += 1
paused++
default:
stopped += 1
stopped++
}
}
cs.Paused = paused

View File

@ -480,9 +480,8 @@ func (r *Runtime) setupSlirp4netns(ctr *Container) error {
if havePortMapping {
if isSlirpHostForward {
return r.setupRootlessPortMappingViaSlirp(ctr, cmd, apiSocket)
} else {
return r.setupRootlessPortMappingViaRLK(ctr, netnsPath)
}
return r.setupRootlessPortMappingViaRLK(ctr, netnsPath)
}
return nil
}

View File

@ -241,9 +241,8 @@ func (p *VolumePlugin) makeErrorResponse(err, endpoint, volName string) error {
}
if volName != "" {
return errors.Wrapf(errors.New(err), "error on %s on volume %s in volume plugin %s", endpoint, volName, p.Name)
} else {
return errors.Wrapf(errors.New(err), "error on %s in volume plugin %s", endpoint, p.Name)
}
return errors.Wrapf(errors.New(err), "error on %s in volume plugin %s", endpoint, p.Name)
}
// Handle error responses from plugin

View File

@ -313,9 +313,8 @@ func (r *Runtime) LoadImageFromSingleImageArchive(ctx context.Context, writer io
if err == nil && src != nil {
if newImages, err := r.ImageRuntime().LoadFromArchiveReference(ctx, src, signaturePolicy, writer); err == nil {
return getImageNames(newImages), nil
} else {
saveErr = err
}
saveErr = err
}
}
return "", errors.Wrapf(saveErr, "error pulling image")

View File

@ -45,7 +45,7 @@ func (v *Volume) mount() error {
// If the count is non-zero, the volume is already mounted.
// Nothing to do.
if v.state.MountCount > 0 {
v.state.MountCount += 1
v.state.MountCount++
logrus.Debugf("Volume %s mount count now at %d", v.Name(), v.state.MountCount)
return v.save()
}
@ -67,7 +67,7 @@ func (v *Volume) mount() error {
return err
}
v.state.MountCount += 1
v.state.MountCount++
v.state.MountPoint = mountPoint
return v.save()
}
@ -109,7 +109,7 @@ func (v *Volume) mount() error {
logrus.Debugf("Mounted volume %s", v.Name())
// Increment the mount counter
v.state.MountCount += 1
v.state.MountCount++
logrus.Debugf("Volume %s mount count now at %d", v.Name(), v.state.MountCount)
return v.save()
}
@ -152,7 +152,7 @@ func (v *Volume) unmount(force bool) error {
}
if !force {
v.state.MountCount -= 1
v.state.MountCount--
} else {
v.state.MountCount = 0
}

View File

@ -62,7 +62,7 @@ func handleHeadAndGet(w http.ResponseWriter, r *http.Request, decoder *schema.De
w.Header().Add(copy.XDockerContainerPathStatHeader, statHeader)
}
if errors.Cause(err) == define.ErrNoSuchCtr || errors.Cause(err) == copy.ENOENT {
if errors.Cause(err) == define.ErrNoSuchCtr || errors.Cause(err) == copy.ErrENOENT {
// 404 is returned for an absent container and path. The
// clients must deal with it accordingly.
utils.Error(w, "Not found.", http.StatusNotFound, err)

View File

@ -130,10 +130,9 @@ func WaitContainerLibpod(w http.ResponseWriter, r *http.Request) {
if errors.Cause(err) == define.ErrNoSuchCtr {
ContainerNotFound(w, name, err)
return
} else {
InternalServerError(w, err)
return
}
InternalServerError(w, err)
return
}
WriteResponse(w, http.StatusOK, strconv.Itoa(int(exitCode)))
}
@ -200,9 +199,8 @@ func waitRemoved(ctrWait containerWaitFn) (int32, error) {
code, err := ctrWait(define.ContainerStateUnknown)
if err != nil && errors.Cause(err) == define.ErrNoSuchCtr {
return code, nil
} else {
return code, err
}
return code, err
}
func waitNextExit(ctrWait containerWaitFn) (int32, error) {

View File

@ -30,7 +30,7 @@ func Stat(ctx context.Context, nameOrID string, path string) (*entities.Containe
var finalErr error
if response.StatusCode == http.StatusNotFound {
finalErr = copy.ENOENT
finalErr = copy.ErrENOENT
} else if response.StatusCode != http.StatusOK {
finalErr = errors.New(response.Status)
}

View File

@ -16,9 +16,9 @@ import (
// base64 encoded JSON payload of stating a path in a container.
const XDockerContainerPathStatHeader = "X-Docker-Container-Path-Stat"
// ENOENT mimics the stdlib's ENOENT and can be used to implement custom logic
// ErrENOENT mimics the stdlib's ErrENOENT and can be used to implement custom logic
// while preserving the user-visible error message.
var ENOENT = errors.New("No such file or directory")
var ErrENOENT = errors.New("No such file or directory")
// FileInfo describes a file or directory and is returned by
// (*CopyItem).Stat().
@ -70,7 +70,7 @@ func ResolveHostPath(path string) (*FileInfo, error) {
statInfo, err := os.Stat(resolvedHostPath)
if err != nil {
if os.IsNotExist(err) {
return nil, ENOENT
return nil, ErrENOENT
}
return nil, err
}

View File

@ -31,7 +31,7 @@ type NetworkReloadOptions struct {
// NetworkReloadReport describes the results of reloading a container network.
type NetworkReloadReport struct {
// nolint:stylecheck
// nolint:stylecheck,golint
Id string
Err error
}

View File

@ -35,7 +35,7 @@ func (ic *ContainerEngine) containerStat(container *libpod.Container, containerM
// ENOENT let's the API handlers return the correct status code
// which is crucial for the remote client.
if os.IsNotExist(err) || strings.Contains(statInfoErr.Error(), "o such file or directory") {
statInfoErr = copy.ENOENT
statInfoErr = copy.ErrENOENT
}
// If statInfo is nil, there's nothing we can do anymore. A
// non-nil statInfo may indicate a symlink where we must have
@ -129,7 +129,7 @@ func secureStat(root string, path string) (*buildahCopiah.StatForItem, error) {
stat, exists := globStats[0].Results[glob] // only one glob passed, so that's okay
if !exists {
return nil, copy.ENOENT
return nil, copy.ErrENOENT
}
var statErr error

View File

@ -40,10 +40,9 @@ func (ir *ImageEngine) Exists(_ context.Context, nameOrID string) (*entities.Boo
if err != nil {
if errors.Cause(err) == define.ErrMultipleImages {
return &entities.BoolReport{Value: true}, nil
} else {
if errors.Cause(err) != define.ErrNoSuchImage {
return nil, err
}
}
if errors.Cause(err) != define.ErrNoSuchImage {
return nil, err
}
}
return &entities.BoolReport{Value: err == nil}, nil