From e42c60a40612d1f9de559b3b4cb011396e76f994 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Svantesson?= Date: Wed, 23 Oct 2024 16:10:29 +0200 Subject: [PATCH] fix: linting --- internal/controller.go | 12 ++---------- internal/main.go | 7 ++----- internal/repository.go | 3 +++ 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/internal/controller.go b/internal/controller.go index 571e4a9..e0d280b 100644 --- a/internal/controller.go +++ b/internal/controller.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/http" "os" "path" @@ -41,13 +40,6 @@ type FileController struct { operationChannel chan string } -var ( - // defaultChartIndex an empty chart index - defaultChartIndex = `apiVersion: v1 -generated: "2019-11-01T17:04:16Z" -entries:` -) - // NewFileController creates a new file controller func NewFileController(cache Storage, storage Storage, repositories []Repository, config Config) (*FileController, error) { chartsPath := config.HTTP.ChartPath @@ -141,7 +133,7 @@ func (ctrl *FileController) PostChart(w http.ResponseWriter, r *http.Request, ps repo := ps.ByName("repo") log.Debugf("PostChart, repo: %s\n", repo) - content, err := ioutil.ReadAll(r.Body) + content, err := io.ReadAll(r.Body) if err != nil { msg := fmt.Sprintf("Failed to load payload: %s", err) w.WriteHeader(500) @@ -175,7 +167,7 @@ func (ctrl *FileController) PostChart(w http.ResponseWriter, r *http.Request, ps filename = filepath.Join(folder, ChartFolder, filename) log.Debugf("PostChart, filename: %s\n", filename) - err = ctrl.writeFileToCache(filename, ioutil.NopCloser(bytes.NewReader(content))) + err = ctrl.writeFileToCache(filename, io.NopCloser(bytes.NewReader(content))) if err != nil { msg := fmt.Sprintf("Error when saving the file into cache: %s", err) w.WriteHeader(500) diff --git a/internal/main.go b/internal/main.go index b7aff61..cb9d749 100644 --- a/internal/main.go +++ b/internal/main.go @@ -44,11 +44,8 @@ func main() { ticker := time.NewTicker(config.Cache.CleanInterval) go func(ticker *time.Ticker) { cache.RemoveUnusedArtifacts(controller) - for { - select { - case <-ticker.C: - cache.RemoveUnusedArtifacts(controller) - } + for range ticker.C { + cache.RemoveUnusedArtifacts(controller) } }(ticker) } diff --git a/internal/repository.go b/internal/repository.go index 3a829ff..d50a2b8 100644 --- a/internal/repository.go +++ b/internal/repository.go @@ -47,6 +47,9 @@ func (r *HTTPRepository) DownloadFile(filePath string) (io.ReadCloser, error) { u.Path = path.Join(u.Path, filePath) request, err := http.NewRequest(http.MethodGet, u.String(), nil) + if err != nil { + return nil, err + } for key, values := range r.header { for _, value := range values { request.Header.Add(key, value)