From ef2c44438c24e3eac661d83b33d3889a3107922d Mon Sep 17 00:00:00 2001 From: glidea <740696441@qq.com> Date: Thu, 5 Jun 2025 23:46:54 +0800 Subject: [PATCH] fix lint --- .golangci.yml | 1 - pkg/api/rss/rss.go | 6 ++++-- pkg/llm/openai.go | 2 -- pkg/notify/channel/channel.go | 1 + pkg/notify/route/route_test.go | 2 +- pkg/rewrite/rewrite.go | 4 +++- pkg/util/crawl/crawl.go | 14 +++++++++----- 7 files changed, 18 insertions(+), 12 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 922fcd4..7818eb1 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -28,7 +28,6 @@ linters: - importas - inamedparam - intrange - - lll - maintidx - nestif - nlreturn diff --git a/pkg/api/rss/rss.go b/pkg/api/rss/rss.go index 6f5e2ab..79afa77 100644 --- a/pkg/api/rss/rss.go +++ b/pkg/api/rss/rss.go @@ -16,7 +16,6 @@ package rss import ( - "fmt" "net" "net/http" "text/template" @@ -185,12 +184,13 @@ func (s *server) rss(w http.ResponseWriter, r *http.Request) { }) if err != nil { http.Error(w, err.Error(), http.StatusBadRequest) // TODO: standardize error handling. + return } // Render and convert to RSS. rssObj := &feeds.Feed{ - Title: fmt.Sprintf("Zenfeed RSS - %s", ps.Encode()), + Title: "Zenfeed RSS - " + ps.Encode(), Description: "Powered by Github Zenfeed - https://github.com/glidea/zenfeed. If you use Folo, please enable 'Appearance - Content - Render inline styles'", Items: make([]*feeds.Item, 0, len(queryResult.Feeds)), } @@ -203,6 +203,7 @@ func (s *server) rss(w http.ResponseWriter, r *http.Request) { if err = s.Config().contentHTMLTemplate.Execute(buf, feed.Labels.Map()); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) + return } @@ -218,6 +219,7 @@ func (s *server) rss(w http.ResponseWriter, r *http.Request) { if err = rssObj.WriteRss(w); err != nil { log.Error(ctx, errors.Wrap(err, "write rss response")) + return } } diff --git a/pkg/llm/openai.go b/pkg/llm/openai.go index b458449..3b23804 100644 --- a/pkg/llm/openai.go +++ b/pkg/llm/openai.go @@ -18,7 +18,6 @@ package llm import ( "context" "encoding/json" - "fmt" "github.com/pkg/errors" oai "github.com/sashabaranov/go-openai" @@ -132,7 +131,6 @@ func (o *openai) Embedding(ctx context.Context, s string) (value []float32, err EncodingFormat: oai.EmbeddingEncodingFormatFloat, }) if err != nil { - fmt.Println(s) return nil, errors.Wrap(err, "create embeddings") } if len(vec.Data) == 0 { diff --git a/pkg/notify/channel/channel.go b/pkg/notify/channel/channel.go index 78f639a..6a9ba3a 100644 --- a/pkg/notify/channel/channel.go +++ b/pkg/notify/channel/channel.go @@ -127,6 +127,7 @@ func (c *aggrChannel) Send(ctx context.Context, receiver Receiver, group *route. if receiver.Webhook != nil && c.webhook != nil { return c.send(ctx, receiver, group, c.webhook, "webhook") } + return nil } diff --git a/pkg/notify/route/route_test.go b/pkg/notify/route/route_test.go index 9884815..0cf8b74 100644 --- a/pkg/notify/route/route_test.go +++ b/pkg/notify/route/route_test.go @@ -537,7 +537,7 @@ func TestConfig_Validate(t *testing.T) { }, }, wantErr: true, - errMsg: "invalid sub_route: invalid matcher: invalid matcher", + errMsg: "invalid sub_route: invalid matchers: new label filter", }, { name: "Valid nested sub-route", diff --git a/pkg/rewrite/rewrite.go b/pkg/rewrite/rewrite.go index f8cc9a7..770a3c2 100644 --- a/pkg/rewrite/rewrite.go +++ b/pkg/rewrite/rewrite.go @@ -101,7 +101,7 @@ type Rule struct { Label string } -func (r *Rule) Validate() error { //nolint:cyclop +func (r *Rule) Validate() error { //nolint:cyclop,gocognit,funlen // If. if len(r.If) > 0 { if_, err := model.NewLabelFilters(r.If) @@ -358,6 +358,7 @@ func (r *rewriter) transformTextCrawl(ctx context.Context, crawler crawl.Crawler if err != nil { return "", errors.Wrapf(err, "crawl %s", url) } + return string(mdBytes), nil } @@ -383,6 +384,7 @@ func (r *rewriter) transformTextHack(text string) string { text = strings.ReplaceAll(text, "```html", "") text = strings.ReplaceAll(text, "```markdown", "") text = strings.ReplaceAll(text, "```", "") + return text } diff --git a/pkg/util/crawl/crawl.go b/pkg/util/crawl/crawl.go index 700e73d..5a91605 100644 --- a/pkg/util/crawl/crawl.go +++ b/pkg/util/crawl/crawl.go @@ -48,7 +48,7 @@ func (c *local) Markdown(ctx context.Context, u string) ([]byte, error) { if err != nil { return nil, errors.Wrapf(err, "fetch %s", u) } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() // Parse the response. if resp.StatusCode != http.StatusOK { @@ -107,7 +107,7 @@ func (c *local) getRobotsData(ctx context.Context, host string) (*robotstxt.Robo if err != nil { return nil, errors.Wrapf(err, "fetch %s", robotsURL) } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() // Parse the response. switch resp.StatusCode { @@ -117,11 +117,15 @@ func (c *local) getRobotsData(ctx context.Context, host string) (*robotstxt.Robo return nil, errors.Wrapf(err, "parse robots.txt from %s", robotsURL) } c.robotsDataCache.Store(host, data) + return data, nil + case http.StatusNotFound: data := &robotstxt.RobotsData{} c.robotsDataCache.Store(host, data) + return data, nil + case http.StatusUnauthorized, http.StatusForbidden: return nil, errors.Errorf("access to %s denied (status %d)", robotsURL, resp.StatusCode) default: @@ -145,7 +149,7 @@ func NewJina(token string) Crawler { } func (c *jina) Markdown(ctx context.Context, u string) ([]byte, error) { - proxyURL := fmt.Sprintf("https://r.jina.ai/%s", u) + proxyURL := "https://r.jina.ai/" + u req, err := http.NewRequestWithContext(ctx, http.MethodGet, proxyURL, nil) if err != nil { return nil, errors.Wrapf(err, "create request for %s", u) @@ -154,14 +158,14 @@ func (c *jina) Markdown(ctx context.Context, u string) ([]byte, error) { req.Header.Set("X-Engine", "browser") req.Header.Set("X-Robots-Txt", userAgent) if c.token != "" { - req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", c.token)) + req.Header.Set("Authorization", "Bearer "+c.token) } resp, err := c.hc.Do(req) if err != nil { return nil, errors.Wrapf(err, "fetch %s", proxyURL) } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() if resp.StatusCode != http.StatusOK { return nil, errors.Errorf("received non-200 status code %d from %s", resp.StatusCode, proxyURL)