Fix some small things

This commit is contained in:
Jan-Lukas Else 2022-08-07 12:46:49 +02:00
parent ea0f1bfe05
commit 38e8ac934f
5 changed files with 17 additions and 23 deletions

View File

@ -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"

View File

@ -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),

View File

@ -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)

View File

@ -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")

View File

@ -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 {