From 632412c10ef0603086514650b6993c037ec69d48 Mon Sep 17 00:00:00 2001 From: Nazar Kanaev Date: Thu, 2 Feb 2023 22:06:27 +0000 Subject: [PATCH] go fmt --- src/assets/assetsfs.go | 1 + src/content/readability/readability.go | 6 ++--- src/content/sanitizer/sanitizer.go | 2 -- src/content/silo/url.go | 16 ++++++------- src/content/silo/url_test.go | 32 +++++++++++++------------- src/platform/fixconsole_default.go | 1 + src/platform/fixconsole_windows.go | 23 ++++++++++-------- src/platform/gui.go | 1 + src/platform/guiless.go | 1 + src/platform/icon_mac.go | 1 + src/platform/icon_win.go | 1 + src/platform/open_etc.go | 1 + src/platform/open_mac.go | 1 + src/platform/open_win.go | 1 + src/server/routes.go | 14 +++++------ src/storage/item.go | 10 ++++---- 16 files changed, 61 insertions(+), 51 deletions(-) diff --git a/src/assets/assetsfs.go b/src/assets/assetsfs.go index 29f3a36..05e6a9d 100644 --- a/src/assets/assetsfs.go +++ b/src/assets/assetsfs.go @@ -1,3 +1,4 @@ +//go:build release // +build release package assets diff --git a/src/content/readability/readability.go b/src/content/readability/readability.go index 86e9086..b7342bc 100644 --- a/src/content/readability/readability.go +++ b/src/content/readability/readability.go @@ -60,9 +60,9 @@ func ExtractContent(page io.Reader) (string, error) { best = body break } - if best == nil { - return "", errors.New("failed to extract content") - } + if best == nil { + return "", errors.New("failed to extract content") + } } //log.Printf("[Readability] TopCandidate: %v", topCandidate) diff --git a/src/content/sanitizer/sanitizer.go b/src/content/sanitizer/sanitizer.go index 7789f42..bebdf8c 100644 --- a/src/content/sanitizer/sanitizer.go +++ b/src/content/sanitizer/sanitizer.go @@ -364,7 +364,6 @@ func isBlockedTag(tagName string) bool { } /* - One or more strings separated by commas, indicating possible image sources for the user agent to use. Each string is composed of: @@ -372,7 +371,6 @@ Each string is composed of: - Optionally, whitespace followed by one of: - A width descriptor (a positive integer directly followed by w). The width descriptor is divided by the source size given in the sizes attribute to calculate the effective pixel density. - A pixel density descriptor (a positive floating point number directly followed by x). - */ func sanitizeSrcsetAttr(baseURL, value string) string { var sanitizedSources []string diff --git a/src/content/silo/url.go b/src/content/silo/url.go index 38b00dc..463a97d 100644 --- a/src/content/silo/url.go +++ b/src/content/silo/url.go @@ -6,12 +6,12 @@ import ( ) func RedirectURL(link string) string { - if strings.HasPrefix(link, "https://www.google.com/url?") { - if u, err := url.Parse(link); err == nil { - if u2 := u.Query().Get("url"); u2 != "" { - return u2 - } - } - } - return link + if strings.HasPrefix(link, "https://www.google.com/url?") { + if u, err := url.Parse(link); err == nil { + if u2 := u.Query().Get("url"); u2 != "" { + return u2 + } + } + } + return link } diff --git a/src/content/silo/url_test.go b/src/content/silo/url_test.go index 3963843..523db07 100644 --- a/src/content/silo/url_test.go +++ b/src/content/silo/url_test.go @@ -3,22 +3,22 @@ package silo import "testing" func TestRedirectURL(t *testing.T) { - link := "https://www.google.com/url?rct=j&sa=t&url=https://www.cryptoglobe.com/latest/2022/08/investment-strategist-lyn-alden-explains-why-she-is-still-bullish-on-bitcoin-long-term/&ct=ga&cd=CAIyGjlkMjI1NjUyODE3ODFjMDQ6Y29tOmVuOlVT&usg=AOvVaw16C2fJtw6m8QVEbto2HCKK" - want := "https://www.cryptoglobe.com/latest/2022/08/investment-strategist-lyn-alden-explains-why-she-is-still-bullish-on-bitcoin-long-term/" - have := RedirectURL(link) - if have != want { - t.Logf("want: %s", want) - t.Logf("have: %s", have) - t.Fail() - } + link := "https://www.google.com/url?rct=j&sa=t&url=https://www.cryptoglobe.com/latest/2022/08/investment-strategist-lyn-alden-explains-why-she-is-still-bullish-on-bitcoin-long-term/&ct=ga&cd=CAIyGjlkMjI1NjUyODE3ODFjMDQ6Y29tOmVuOlVT&usg=AOvVaw16C2fJtw6m8QVEbto2HCKK" + want := "https://www.cryptoglobe.com/latest/2022/08/investment-strategist-lyn-alden-explains-why-she-is-still-bullish-on-bitcoin-long-term/" + have := RedirectURL(link) + if have != want { + t.Logf("want: %s", want) + t.Logf("have: %s", have) + t.Fail() + } - link = "https://example.com" - if RedirectURL(link) != link { - t.Fail() - } + link = "https://example.com" + if RedirectURL(link) != link { + t.Fail() + } - link = "https://example.com/url?url=test.com" - if RedirectURL(link) != link { - t.Fail() - } + link = "https://example.com/url?url=test.com" + if RedirectURL(link) != link { + t.Fail() + } } diff --git a/src/platform/fixconsole_default.go b/src/platform/fixconsole_default.go index 1f826c5..8b2c9c4 100644 --- a/src/platform/fixconsole_default.go +++ b/src/platform/fixconsole_default.go @@ -1,3 +1,4 @@ +//go:build !windows // +build !windows package platform diff --git a/src/platform/fixconsole_windows.go b/src/platform/fixconsole_windows.go index 03c5641..39ea588 100644 --- a/src/platform/fixconsole_windows.go +++ b/src/platform/fixconsole_windows.go @@ -58,17 +58,20 @@ var oldStdin, oldStdout, oldStderr *os.File // // Net result is as follows. // Before: -// SHELL NON-REDIRECTED REDIRECTED -// explorer.exe no console n/a -// cmd.exe broken works -// powershell broken broken -// WSL bash broken works +// +// SHELL NON-REDIRECTED REDIRECTED +// explorer.exe no console n/a +// cmd.exe broken works +// powershell broken broken +// WSL bash broken works +// // After -// SHELL NON-REDIRECTED REDIRECTED -// explorer.exe no console n/a -// cmd.exe works works -// powershell works broken -// WSL bash works works +// +// SHELL NON-REDIRECTED REDIRECTED +// explorer.exe no console n/a +// cmd.exe works works +// powershell works broken +// WSL bash works works // // We don't seem to make anything worse, at least. func FixConsoleIfNeeded() error { diff --git a/src/platform/gui.go b/src/platform/gui.go index f08a645..5c54449 100644 --- a/src/platform/gui.go +++ b/src/platform/gui.go @@ -1,3 +1,4 @@ +//go:build macos || windows // +build macos windows package platform diff --git a/src/platform/guiless.go b/src/platform/guiless.go index 702fd7e..58c1414 100644 --- a/src/platform/guiless.go +++ b/src/platform/guiless.go @@ -1,3 +1,4 @@ +//go:build !windows && !macos // +build !windows,!macos package platform diff --git a/src/platform/icon_mac.go b/src/platform/icon_mac.go index 5bd5bec..1840f9e 100644 --- a/src/platform/icon_mac.go +++ b/src/platform/icon_mac.go @@ -1,3 +1,4 @@ +//go:build macos // +build macos package platform diff --git a/src/platform/icon_win.go b/src/platform/icon_win.go index e5a9ba2..aef6bcd 100644 --- a/src/platform/icon_win.go +++ b/src/platform/icon_win.go @@ -1,3 +1,4 @@ +//go:build windows // +build windows package platform diff --git a/src/platform/open_etc.go b/src/platform/open_etc.go index df73778..de5e978 100644 --- a/src/platform/open_etc.go +++ b/src/platform/open_etc.go @@ -1,3 +1,4 @@ +//go:build !windows && !darwin // +build !windows,!darwin package platform diff --git a/src/platform/open_mac.go b/src/platform/open_mac.go index 471cc8a..7d7ae20 100644 --- a/src/platform/open_mac.go +++ b/src/platform/open_mac.go @@ -1,3 +1,4 @@ +//go:build darwin // +build darwin package platform diff --git a/src/platform/open_win.go b/src/platform/open_win.go index ecacf75..c4f01eb 100644 --- a/src/platform/open_win.go +++ b/src/platform/open_win.go @@ -1,3 +1,4 @@ +//go:build windows // +build windows package platform diff --git a/src/server/routes.go b/src/server/routes.go index 1e1ebe5..1ab18a4 100644 --- a/src/server/routes.go +++ b/src/server/routes.go @@ -244,7 +244,7 @@ func (s *Server) handleFeedList(c *router.Context) { if len(items) > 0 { s.db.CreateItems(items) s.db.SetFeedSize(feed.Id, len(items)) - s.db.SyncSearch() + s.db.SyncSearch() } s.worker.FindFeedFavicon(*feed) @@ -476,9 +476,9 @@ func (s *Server) handleOPMLExport(c *router.Context) { func (s *Server) handlePageCrawl(c *router.Context) { url := c.Req.URL.Query().Get("url") - if newUrl := silo.RedirectURL(url); newUrl != "" { - url = newUrl - } + if newUrl := silo.RedirectURL(url); newUrl != "" { + url = newUrl + } if content := silo.VideoIFrame(url); content != "" { c.JSON(http.StatusOK, map[string]string{ "content": sanitizer.Sanitize(url, content), @@ -494,9 +494,9 @@ func (s *Server) handlePageCrawl(c *router.Context) { } content, err := readability.ExtractContent(strings.NewReader(body)) if err != nil { - c.JSON(http.StatusOK, map[string]string{ - "content": "error: " + err.Error(), - }) + c.JSON(http.StatusOK, map[string]string{ + "content": "error: " + err.Error(), + }) return } content = sanitizer.Sanitize(url, content) diff --git a/src/storage/item.go b/src/storage/item.go index de44dfc..49772fe 100644 --- a/src/storage/item.go +++ b/src/storage/item.go @@ -300,11 +300,11 @@ var ( // Delete old articles from the database to cleanup space. // // The rules: -// * Never delete starred entries. -// * Keep at least the same amount of articles the feed provides (default: 50). -// This prevents from deleting items for rarely updated and/or ever-growing -// feeds which might eventually reappear as unread. -// * Keep entries for a certain period (default: 90 days). +// - Never delete starred entries. +// - Keep at least the same amount of articles the feed provides (default: 50). +// This prevents from deleting items for rarely updated and/or ever-growing +// feeds which might eventually reappear as unread. +// - Keep entries for a certain period (default: 90 days). func (s *Storage) DeleteOldItems() { rows, err := s.db.Query(` select