From 9f376db0f4647a90c2c9753a92abb19cfaa7efcb Mon Sep 17 00:00:00 2001 From: Nazar Kanaev Date: Fri, 19 Mar 2021 00:06:48 +0000 Subject: [PATCH] gofmt --- bin/generate_versioninfo.go | 4 ++-- bin/package_macos.go | 4 ++-- src/assets/assetsfs.go | 2 +- src/auth/auth.go | 8 ++++---- src/auth/middleware.go | 4 ++-- src/crawler/finder_test.go | 10 +++++----- src/main.go | 2 +- src/opml/opml.go | 8 ++++---- src/opml/opml_test.go | 15 +++++++-------- src/opml/read.go | 10 +++++----- src/opml/read_test.go | 17 ++++++++--------- src/platform/gui.go | 2 +- src/router/context.go | 6 +++--- src/router/match_test.go | 4 ++-- src/router/router.go | 2 +- src/server/routes.go | 6 +++--- src/server/server.go | 6 +++--- src/storage/feed.go | 2 +- src/storage/http.go | 2 +- src/storage/item.go | 2 +- src/storage/migration.go | 8 ++++---- src/storage/storage.go | 2 +- src/worker/crawler.go | 2 +- src/worker/worker.go | 4 ++-- 24 files changed, 65 insertions(+), 67 deletions(-) diff --git a/bin/generate_versioninfo.go b/bin/generate_versioninfo.go index b05f9fb..390cb70 100644 --- a/bin/generate_versioninfo.go +++ b/bin/generate_versioninfo.go @@ -1,12 +1,12 @@ package main import ( - "io/ioutil" "flag" + "io/ioutil" "strings" ) -var rsrc = `1 VERSIONINFO +var rsrc = `1 VERSIONINFO FILEVERSION {VERSION_COMMA},0,0 PRODUCTVERSION {VERSION_COMMA},0,0 BEGIN diff --git a/bin/package_macos.go b/bin/package_macos.go index 43c0b2f..8cd24d8 100644 --- a/bin/package_macos.go +++ b/bin/package_macos.go @@ -85,9 +85,9 @@ func main() { for _, res := range []int{1024, 512, 256, 128, 64, 32, 16} { outfile := fmt.Sprintf("icon_%dx%d.png", res, res) if res == 1024 || res == 64 { - outfile = fmt.Sprintf("icon_%dx%d@2x.png", res / 2, res / 2) + outfile = fmt.Sprintf("icon_%dx%d@2x.png", res/2, res/2) } - cmd := []string { + cmd := []string{ "sips", "-s", "format", "png", "--resampleWidth", strconv.Itoa(res), iconFile, "--out", path.Join(iconsetDir, outfile), } diff --git a/src/assets/assetsfs.go b/src/assets/assetsfs.go index 1cb605d..29f3a36 100644 --- a/src/assets/assetsfs.go +++ b/src/assets/assetsfs.go @@ -11,5 +11,5 @@ import "embed" var embedded embed.FS func init() { - FS.embedded = &embedded + FS.embedded = &embedded } diff --git a/src/auth/auth.go b/src/auth/auth.go index 1a8978f..f895e3f 100644 --- a/src/auth/auth.go +++ b/src/auth/auth.go @@ -33,10 +33,10 @@ func Authenticate(rw http.ResponseWriter, username, password, basepath string) { func Logout(rw http.ResponseWriter, basepath string) { http.SetCookie(rw, &http.Cookie{ - Name: "auth", - Value: "", - MaxAge: -1, - Path: basepath, + Name: "auth", + Value: "", + MaxAge: -1, + Path: basepath, }) } diff --git a/src/auth/middleware.go b/src/auth/middleware.go index 03dc8bb..d7b1e76 100644 --- a/src/auth/middleware.go +++ b/src/auth/middleware.go @@ -20,7 +20,7 @@ func unsafeMethod(method string) bool { } func (m *Middleware) Handler(c *router.Context) { - if strings.HasPrefix(c.Req.URL.Path, m.BasePath + m.Public) { + if strings.HasPrefix(c.Req.URL.Path, m.BasePath+m.Public) { c.Next() return } @@ -46,7 +46,7 @@ func (m *Middleware) Handler(c *router.Context) { } else { c.HTML(http.StatusOK, assets.Template("login.html"), map[string]string{ "username": username, - "error": "Invalid username/password", + "error": "Invalid username/password", }) return } diff --git a/src/crawler/finder_test.go b/src/crawler/finder_test.go index a0f596f..0fa6399 100644 --- a/src/crawler/finder_test.go +++ b/src/crawler/finder_test.go @@ -1,8 +1,8 @@ package crawler import ( - "testing" "reflect" + "testing" ) const base = "http://example.com" @@ -11,7 +11,7 @@ func TestFindFeedsInvalidHTML(t *testing.T) { x := `some nonsense` r := FindFeeds(x, base) if len(r) != 0 { - t.Fatal("not expecting results") + t.Fatal("not expecting results") } } @@ -34,8 +34,8 @@ func TestFindFeedsLinks(t *testing.T) { have := FindFeeds(x, base) want := map[string]string{ - base + "/feed.xml": "rss with title", - base + "/atom.xml": "", + base + "/feed.xml": "rss with title", + base + "/atom.xml": "", base + "/feed.json": "", } if !reflect.DeepEqual(have, want) { @@ -63,7 +63,7 @@ func TestFindFeedsGuess(t *testing.T) { have := FindFeeds(body, base) want := map[string]string{ base + "/feed.xml": "", - base + "/news": "", + base + "/news": "", } if !reflect.DeepEqual(want, have) { t.Logf("want: %#v", want) diff --git a/src/main.go b/src/main.go index cfb121c..1c26e0d 100644 --- a/src/main.go +++ b/src/main.go @@ -19,7 +19,7 @@ var GitHash string = "unknown" func main() { log.SetOutput(os.Stdout) - log.SetFlags(log.Ldate|log.Ltime|log.Lshortfile) + log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile) var addr, db, authfile, certfile, keyfile string var ver, open bool diff --git a/src/opml/opml.go b/src/opml/opml.go index b6b92c7..1d47d21 100644 --- a/src/opml/opml.go +++ b/src/opml/opml.go @@ -1,9 +1,9 @@ package opml import ( - "strings" - "html" "fmt" + "html" + "strings" ) type Folder struct { @@ -36,7 +36,7 @@ func (f Folder) outline(level int) string { prefix := strings.Repeat(indent, level) if level > 0 { - builder.WriteString(prefix + fmt.Sprintf(`` + nl, e(f.Title))) + builder.WriteString(prefix + fmt.Sprintf(``+nl, e(f.Title))) } for _, folder := range f.Folders { builder.WriteString(folder.outline(level + 1)) @@ -52,7 +52,7 @@ func (f Folder) outline(level int) string { func (f Feed) outline(level int) string { return strings.Repeat(indent, level) + fmt.Sprintf( - `` + nl, + ``+nl, e(f.Title), e(f.FeedUrl), e(f.SiteUrl), ) } diff --git a/src/opml/opml_test.go b/src/opml/opml_test.go index 4a97b1b..30f3bdc 100644 --- a/src/opml/opml_test.go +++ b/src/opml/opml_test.go @@ -5,28 +5,27 @@ import ( "testing" ) - func TestOPML(t *testing.T) { have := (Folder{ Title: "", Feeds: []Feed{ - Feed{ - Title: "title1", + { + Title: "title1", FeedUrl: "https://baz.com/feed.xml", SiteUrl: "https://baz.com/", }, }, Folders: []Folder{ - Folder{ + { Title: "sub", Feeds: []Feed{ - Feed{ - Title: "subtitle1", + { + Title: "subtitle1", FeedUrl: "https://foo.com/feed.xml", SiteUrl: "https://foo.com/", }, - Feed{ - Title: "&>", + { + Title: "&>", FeedUrl: "https://bar.com/feed.xml", SiteUrl: "https://bar.com/", }, diff --git a/src/opml/read.go b/src/opml/read.go index 9899061..1ea1f4d 100644 --- a/src/opml/read.go +++ b/src/opml/read.go @@ -11,11 +11,11 @@ type opml struct { } type outline struct { - Type string `xml:"type,attr,omitempty"` - Title string `xml:"text,attr"` - FeedUrl string `xml:"xmlUrl,attr,omitempty"` - SiteUrl string `xml:"htmlUrl,attr,omitempty"` - Outlines []outline `xml:"outline,omitempty"` + Type string `xml:"type,attr,omitempty"` + Title string `xml:"text,attr"` + FeedUrl string `xml:"xmlUrl,attr,omitempty"` + SiteUrl string `xml:"htmlUrl,attr,omitempty"` + Outlines []outline `xml:"outline,omitempty"` } func buildFolder(title string, outlines []outline) Folder { diff --git a/src/opml/read_test.go b/src/opml/read_test.go index 85adaa9..93ce9cd 100644 --- a/src/opml/read_test.go +++ b/src/opml/read_test.go @@ -6,7 +6,6 @@ import ( "testing" ) - func TestParse(t *testing.T) { have, _ := Parse(strings.NewReader(` @@ -27,30 +26,30 @@ func TestParse(t *testing.T) { want := Folder{ Title: "", Feeds: []Feed{ - Feed{ - Title: "title1", + { + Title: "title1", FeedUrl: "https://baz.com/feed.xml", SiteUrl: "https://baz.com/", }, }, Folders: []Folder{ - Folder{ + { Title: "sub", Feeds: []Feed{ - Feed{ - Title: "subtitle1", + { + Title: "subtitle1", FeedUrl: "https://foo.com/feed.xml", SiteUrl: "https://foo.com/", }, - Feed{ - Title: "&>", + { + Title: "&>", FeedUrl: "https://bar.com/feed.xml", SiteUrl: "https://bar.com/", }, }, }, }, - } + } if !reflect.DeepEqual(want, have) { t.Logf("want: %#v", want) t.Logf("have: %#v", have) diff --git a/src/platform/gui.go b/src/platform/gui.go index bc1308c..d64ff6e 100644 --- a/src/platform/gui.go +++ b/src/platform/gui.go @@ -3,8 +3,8 @@ package platform import ( - "github.com/nkanaev/yarr/src/systray" "github.com/nkanaev/yarr/src/server" + "github.com/nkanaev/yarr/src/systray" ) func Start(s *server.Handler) { diff --git a/src/router/context.go b/src/router/context.go index b0157ab..2510009 100644 --- a/src/router/context.go +++ b/src/router/context.go @@ -10,10 +10,10 @@ import ( ) type Context struct { - Req *http.Request - Out http.ResponseWriter + Req *http.Request + Out http.ResponseWriter - Vars map[string]string + Vars map[string]string chain []Handler index int diff --git a/src/router/match_test.go b/src/router/match_test.go index 3f7ad81..b6554b8 100644 --- a/src/router/match_test.go +++ b/src/router/match_test.go @@ -55,7 +55,7 @@ func TestRouteRegexpStar(t *testing.T) { func TestRegexGroupsPart(t *testing.T) { re := routeRegexp("/foo/:bar/1/:baz") - + expect := map[string]string{"bar": "one", "baz": "two"} actual := regexGroups("/foo/one/1/two", re) @@ -66,7 +66,7 @@ func TestRegexGroupsPart(t *testing.T) { func TestRegexGroupsStar(t *testing.T) { re := routeRegexp("/foo/*bar") - + expect := map[string]string{"bar": "bar/baz/"} actual := regexGroups("/foo/bar/baz/", re) diff --git a/src/router/router.go b/src/router/router.go index 3f0cc3f..c29d8ec 100644 --- a/src/router/router.go +++ b/src/router/router.go @@ -51,7 +51,7 @@ func (r *Router) resolve(path string) *Route { func (r *Router) ServeHTTP(rw http.ResponseWriter, req *http.Request) { // autoclose open base url if r.base != "" && r.base == req.URL.Path { - http.Redirect(rw, req, r.base + "/", http.StatusFound) + http.Redirect(rw, req, r.base+"/", http.StatusFound) return } diff --git a/src/server/routes.go b/src/server/routes.go index 64a897a..7538ad2 100644 --- a/src/server/routes.go +++ b/src/server/routes.go @@ -361,7 +361,7 @@ func (s *Server) handleOPMLExport(c *router.Context) { feed := feed if feed.FolderId == nil { doc.Feeds = append(doc.Feeds, opml.Feed{ - Title: feed.Title, + Title: feed.Title, FeedUrl: feed.FeedLink, SiteUrl: feed.Link, }) @@ -370,7 +370,7 @@ func (s *Server) handleOPMLExport(c *router.Context) { feedsByFolderID[id] = append(feedsByFolderID[id], &feed) } } - + for _, folder := range s.db.ListFolders() { folderFeeds := feedsByFolderID[folder.Id] if len(folderFeeds) == 0 { @@ -379,7 +379,7 @@ func (s *Server) handleOPMLExport(c *router.Context) { opmlfolder := opml.Folder{Title: folder.Title} for _, feed := range folderFeeds { opmlfolder.Feeds = append(opmlfolder.Feeds, opml.Feed{ - Title: feed.Title, + Title: feed.Title, FeedUrl: feed.FeedLink, SiteUrl: feed.Link, }) diff --git a/src/server/server.go b/src/server/server.go index b806088..cc1f958 100644 --- a/src/server/server.go +++ b/src/server/server.go @@ -11,9 +11,9 @@ import ( var BasePath string = "" type Server struct { - Addr string - db *storage.Storage - worker *worker.Worker + Addr string + db *storage.Storage + worker *worker.Worker // auth Username string Password string diff --git a/src/storage/feed.go b/src/storage/feed.go index 1970253..03694c1 100644 --- a/src/storage/feed.go +++ b/src/storage/feed.go @@ -1,8 +1,8 @@ package storage import ( - "log" "html" + "log" "net/url" ) diff --git a/src/storage/http.go b/src/storage/http.go index 8ad2411..dd87ca2 100644 --- a/src/storage/http.go +++ b/src/storage/http.go @@ -14,7 +14,7 @@ type HTTPState struct { } func (s *Storage) ListHTTPStates() map[int64]HTTPState { - result := make(map[int64]HTTPState) + result := make(map[int64]HTTPState) rows, err := s.db.Query(`select feed_id, last_refreshed, last_modified, etag from http_states`) if err != nil { log.Print(err) diff --git a/src/storage/item.go b/src/storage/item.go index 0b906c3..71dc463 100644 --- a/src/storage/item.go +++ b/src/storage/item.go @@ -3,11 +3,11 @@ package storage import ( "encoding/json" "fmt" + xhtml "golang.org/x/net/html" "html" "log" "strings" "time" - xhtml "golang.org/x/net/html" ) type ItemStatus int diff --git a/src/storage/migration.go b/src/storage/migration.go index 4c5df4b..7795e3c 100644 --- a/src/storage/migration.go +++ b/src/storage/migration.go @@ -6,7 +6,7 @@ import ( "log" ) -var migrations = []func(*sql.Tx)error{ +var migrations = []func(*sql.Tx) error{ m01_initial, m02_feed_states_and_errors, m03_on_delete_actions, @@ -17,7 +17,7 @@ var maxVersion = int64(len(migrations)) func migrate(db *sql.DB) error { var version int64 - db.QueryRow("pragma user_version").Scan(&version); + db.QueryRow("pragma user_version").Scan(&version) if version >= maxVersion { return nil @@ -29,7 +29,7 @@ func migrate(db *sql.DB) error { // Migrations altering schema using a sequence of steps due to SQLite limitations. // Must come with `pragma foreign_key_check` at the end. See: // "Making Other Kinds Of Table Schema Changes" - // https://www.sqlite.org/lang_altertable.html + // https://www.sqlite.org/lang_altertable.html trickyAlteration := (v == 3) log.Printf("[migration:%d] starting", v) @@ -56,7 +56,7 @@ func migrate(db *sql.DB) error { func migrateVersion(v int64, db *sql.DB) error { var err error var tx *sql.Tx - migratefunc := migrations[v - 1] + migratefunc := migrations[v-1] if tx, err = db.Begin(); err != nil { log.Printf("[migration:%d] failed to start transaction", v) return err diff --git a/src/storage/storage.go b/src/storage/storage.go index 37b2fa0..94284df 100644 --- a/src/storage/storage.go +++ b/src/storage/storage.go @@ -6,7 +6,7 @@ import ( ) type Storage struct { - db *sql.DB + db *sql.DB } func New(path string) (*Storage, error) { diff --git a/src/worker/crawler.go b/src/worker/crawler.go index 5ab4ddc..c9416f8 100644 --- a/src/worker/crawler.go +++ b/src/worker/crawler.go @@ -5,8 +5,8 @@ import ( "errors" "fmt" "github.com/mmcdole/gofeed" - "github.com/nkanaev/yarr/src/storage" "github.com/nkanaev/yarr/src/crawler" + "github.com/nkanaev/yarr/src/storage" "io/ioutil" "net" "net/http" diff --git a/src/worker/worker.go b/src/worker/worker.go index 5c030d8..58587cf 100644 --- a/src/worker/worker.go +++ b/src/worker/worker.go @@ -3,8 +3,8 @@ package worker import ( "github.com/nkanaev/yarr/src/storage" "log" - "sync/atomic" "runtime" + "sync/atomic" "time" ) @@ -19,7 +19,7 @@ type Worker struct { func NewWorker(db *storage.Storage) *Worker { queueSize := int32(0) return &Worker{ - db: db, + db: db, feedQueue: make(chan storage.Feed, 3000), queueSize: &queueSize, refreshRate: make(chan int64),