Update staticcheck version and fix all warnings (#1381)

This commit is contained in:
Ta-Ching Chen
2019-11-05 18:09:12 +08:00
committed by GitHub
parent 93d4b88d84
commit b9a5588ca9
43 changed files with 122 additions and 219 deletions
+13 -21
View File
@@ -28,7 +28,7 @@ import (
type ArchivePruner struct {
logger *zap.Logger
crdClient *crd.FissionClient
archiveChan chan (string)
archiveChan chan string
stowClient *StowClient
pruneInterval time.Duration
}
@@ -53,18 +53,15 @@ func MakeArchivePruner(logger *zap.Logger, stowClient *StowClient, pruneInterval
// pruneArchives listens to archiveChannel for archive ids that need to be deleted
func (pruner *ArchivePruner) pruneArchives() {
pruner.logger.Debug("listening to archiveChannel to prune archives")
for {
select {
case archiveID := <-pruner.archiveChan:
pruner.logger.Info("sending delete request for archive",
for archiveID := range pruner.archiveChan {
pruner.logger.Info("sending delete request for archive",
zap.String("archive_id", archiveID))
if err := pruner.stowClient.removeFileByID(archiveID); err != nil {
// logging the error and continuing with other deletions.
// hopefully this archive will be deleted in the next iteration.
pruner.logger.Error("ignoring error while deleting archive",
zap.Error(err),
zap.String("archive_id", archiveID))
if err := pruner.stowClient.removeFileByID(archiveID); err != nil {
// logging the error and continuing with other deletions.
// hopefully this archive will be deleted in the next iteration.
pruner.logger.Error("ignoring error while deleting archive",
zap.Error(err),
zap.String("archive_id", archiveID))
}
}
}
}
@@ -134,8 +131,6 @@ func (pruner *ArchivePruner) getOrphanArchives() {
for _, archiveID = range orphanedArchives {
pruner.insertArchive(archiveID)
}
return
}
// Start starts a go routine that listens to a channel for archive IDs that need to deleted.
@@ -144,12 +139,9 @@ func (pruner *ArchivePruner) getOrphanArchives() {
func (pruner *ArchivePruner) Start() {
ticker := time.NewTicker(pruner.pruneInterval * time.Minute)
go pruner.pruneArchives()
for {
select {
case <-ticker.C:
// This method fetches unused archive IDs and sends them to archiveChannel for deletion
// silencing the errors, hoping they go away in next iteration.
pruner.getOrphanArchives()
}
for range ticker.C {
// This method fetches unused archive IDs and sends them to archiveChannel for deletion
// silencing the errors, hoping they go away in next iteration.
pruner.getOrphanArchives()
}
}
+3 -3
View File
@@ -20,7 +20,6 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
@@ -30,6 +29,7 @@ import (
"os"
"strings"
"github.com/pkg/errors"
"go.opencensus.io/plugin/ochttp"
"golang.org/x/net/context/ctxhttp"
@@ -127,7 +127,7 @@ func (c *Client) Download(ctx context.Context, id string, filePath string) error
// quit if file exists
_, err := os.Stat(filePath)
if err == nil || !os.IsNotExist(err) {
return errors.New(fmt.Sprintf("file already exists: %v", filePath))
return errors.Errorf("file already exists: %v", filePath)
}
// create
@@ -175,7 +175,7 @@ func (c *Client) Delete(ctx context.Context, id string) error {
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return errors.New(fmt.Sprintf("HTTP error %v", resp.StatusCode))
return errors.Errorf("HTTP error %v", resp.StatusCode)
}
return nil
+2 -2
View File
@@ -18,7 +18,6 @@ package storagesvc
import (
"encoding/json"
"errors"
"fmt"
"net/http"
"os"
@@ -27,6 +26,7 @@ import (
"github.com/gorilla/mux"
_ "github.com/graymeta/stow/local"
"github.com/pkg/errors"
"go.opencensus.io/plugin/ochttp"
"go.uber.org/zap"
)
@@ -109,7 +109,7 @@ func (ss *StorageService) getIdFromRequest(r *http.Request) (string, error) {
values := r.URL.Query()
ids, ok := values["id"]
if !ok || len(ids) == 0 {
return "", errors.New("Missing `id' query param")
return "", errors.New("missing `id' query param")
}
return ids[0], nil
}