From 8f9b04d662bccb9e57db081c58bec9be41066c2f Mon Sep 17 00:00:00 2001 From: or-shachar Date: Sat, 25 Nov 2023 12:57:51 +0200 Subject: [PATCH] fixed golint errors --- cacheproc/cacheproc.go | 13 ++++++++++++- cachers/counts.go | 2 +- cmd/go-cacher-server/cacher-server.go | 4 ++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/cacheproc/cacheproc.go b/cacheproc/cacheproc.go index 95a8f61..3ab0414 100644 --- a/cacheproc/cacheproc.go +++ b/cacheproc/cacheproc.go @@ -25,9 +25,12 @@ import ( "github.com/bradfitz/go-tool-cache/wire" ) +type cacherCtxKey string + var ( ErrUnknownCommand = errors.New("unknown command") ErrNoOutputID = errors.New("no outputID") + requestIDKey = cacherCtxKey("requestID") ) // Process implements the cmd/go JSON protocol over stdin & stdout via three @@ -68,6 +71,9 @@ func (p *Process) Run(ctx context.Context) error { _ = p.close() }() for { + if err := ctx.Err(); err != nil { + + } var req wire.Request if err := jd.Decode(&req); err != nil { if errors.Is(err, io.EOF) { @@ -89,7 +95,7 @@ func (p *Process) Run(ctx context.Context) error { } wg.Go(func() error { res := &wire.Response{ID: req.ID} - ctx := context.WithValue(ctx, "requestID", &req) + ctx := context.WithValue(ctx, requestIDKey, &req) if err := p.handleRequest(ctx, &req, res); err != nil { res.Err = err.Error() } @@ -99,6 +105,11 @@ func (p *Process) Run(ctx context.Context) error { _ = bw.Flush() return nil }) + select { + case <-ctx.Done(): + break + default: + } } return wg.Wait() } diff --git a/cachers/counts.go b/cachers/counts.go index 29d4808..b764ee4 100644 --- a/cachers/counts.go +++ b/cachers/counts.go @@ -29,7 +29,7 @@ type LocalCacheWithCounts struct { } func (l *LocalCacheWithCounts) Kind() string { - return l.Kind() + return l.cache.Kind() } type RemoteCacheWithCounts struct { diff --git a/cmd/go-cacher-server/cacher-server.go b/cmd/go-cacher-server/cacher-server.go index 197aac9..7c70c46 100644 --- a/cmd/go-cacher-server/cacher-server.go +++ b/cmd/go-cacher-server/cacher-server.go @@ -95,7 +95,7 @@ func (s *server) ServeHTTP(w http.ResponseWriter, r *http.Request) { case strings.HasPrefix(r.URL.Path, "/output/"): s.handleGetOutput(w, r) case r.URL.Path == "/": - io.WriteString(w, "hi") + _, _ = io.WriteString(w, "hi") default: http.Error(w, "not found", http.StatusNotFound) } @@ -150,7 +150,7 @@ func (s *server) handleGetAction(w http.ResponseWriter, r *http.Request) { return } w.Header().Set("Content-Type", "application/json") - json.NewEncoder(w).Encode(&cachers.ActionValue{ + _ = json.NewEncoder(w).Encode(&cachers.ActionValue{ OutputID: outputID, Size: fi.Size(), })