From 38e8ac934fc5bcdf42369c155e438302a74035ea Mon Sep 17 00:00:00 2001 From: Jan-Lukas Else Date: Sun, 7 Aug 2022 12:46:49 +0200 Subject: [PATCH] Fix some small things --- .golangci.yml | 18 ++++++++++-------- activityPub.go | 6 +----- activityStreams.go | 10 +++------- database.go | 4 ++-- postsDb.go | 2 +- 5 files changed, 17 insertions(+), 23 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 0cc6adb..56c7399 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -14,22 +14,24 @@ linters: - gosimple - govet - ineffassign - - structcheck + - staticcheck - typecheck - unused - varcheck # Other linters - - dupl - - gofmt + - asasalint + - bidichk - bodyclose + - containedctx + - contextcheck + - dupl + - durationcheck + - gofmt + - gosec + - makezero - noctx - prealloc - unparam - - durationcheck - - bidichk - - containedctx - - contextcheck - - gosec linters-settings: gosimple: go: "1.19" diff --git a/activityPub.go b/activityPub.go index 307eae0..040a96a 100644 --- a/activityPub.go +++ b/activityPub.go @@ -404,11 +404,7 @@ func (a *goBlog) apAccept(blogName string, blog *configBlog, follow map[string]a func (a *goBlog) apSendProfileUpdates() { for blog, config := range a.cfg.Blogs { - person, err := a.toAsPerson(blog) - if err != nil { - log.Println("Failed to create Person object:", err) - continue - } + person := a.toAsPerson(blog) a.apSendToAllFollowers(blog, map[string]any{ "@context": []string{asContext}, "actor": a.apIri(config), diff --git a/activityStreams.go b/activityStreams.go index fbb85e7..d643413 100644 --- a/activityStreams.go +++ b/activityStreams.go @@ -167,7 +167,7 @@ func (a *goBlog) activityPubId(p *post) string { return fu } -func (a *goBlog) toAsPerson(blog string) (*asPerson, error) { +func (a *goBlog) toAsPerson(blog string) *asPerson { b := a.cfg.Blogs[blog] asBlog := &asPerson{ Context: []string{asContext}, @@ -194,15 +194,11 @@ func (a *goBlog) toAsPerson(blog string) (*asPerson, error) { URL: a.cfg.User.Picture, } } - return asBlog, nil + return asBlog } func (a *goBlog) serveActivityStreams(blog string, w http.ResponseWriter, r *http.Request) { - person, err := a.toAsPerson(blog) - if err != nil { - a.serveError(w, r, "Failed to create ActivityStreams Person", http.StatusInternalServerError) - return - } + person := a.toAsPerson(blog) // Encode buf := bufferpool.Get() defer bufferpool.Put(buf) diff --git a/database.go b/database.go index 9c96147..709c2ab 100644 --- a/database.go +++ b/database.go @@ -103,14 +103,14 @@ func (a *goBlog) openDatabase(file string, logging bool) (*database, error) { if err != nil { return nil, err } - cos := map[string]bool{} + cos := map[string]struct{}{} var co string for rows.Next() { err = rows.Scan(&co) if err != nil { return nil, err } - cos[co] = true + cos[co] = struct{}{} } if _, ok := cos["ENABLE_FTS5"]; !ok { return nil, errors.New("sqlite not compiled with FTS5") diff --git a/postsDb.go b/postsDb.go index 7fb30ea..d1d6fc6 100644 --- a/postsDb.go +++ b/postsDb.go @@ -620,12 +620,12 @@ func (a *goBlog) getRandomPostPath(blog string) (path string, err error) { } func (d *database) allTaxonomyValues(blog string, taxonomy string) ([]string, error) { - var values []string // TODO: Query posts the normal way rows, err := d.query("select distinct value from post_parameters where parameter = @tax and length(coalesce(value, '')) > 0 and path in (select path from posts where blog = @blog and status = @status) order by value", sql.Named("tax", taxonomy), sql.Named("blog", blog), sql.Named("status", statusPublished)) if err != nil { return nil, err } + var values []string var value string for rows.Next() { if err = rows.Scan(&value); err != nil {