Compare commits

...

3 Commits

Author SHA1 Message Date
3addbb50de
Simplify markasread function
All checks were successful
the build was successful
2018-08-15 19:04:44 +02:00
507aff683e
Use gomodule version of redis library 2018-08-15 19:04:15 +02:00
c678fc67da
Add missing deferred body Close calls 2018-08-15 19:03:45 +02:00
7 changed files with 19 additions and 18 deletions

View File

@ -25,7 +25,7 @@ import (
"regexp"
"time"
"github.com/garyburd/redigo/redis"
"github.com/gomodule/redigo/redis"
)
// TokenResponse is the information that we get back from the token endpoint of the user...

View File

@ -33,7 +33,7 @@ import (
"p83.nl/go/ekster/pkg/util"
"github.com/alecthomas/template"
"github.com/garyburd/redigo/redis"
"github.com/gomodule/redigo/redis"
"willnorris.com/go/microformats"
)

View File

@ -30,7 +30,7 @@ import (
"p83.nl/go/ekster/pkg/util"
"p83.nl/go/ekster/pkg/websub"
"github.com/garyburd/redigo/redis"
"github.com/gomodule/redigo/redis"
)
// LeaseSeconds is the default number of seconds we want the subscription to last

View File

@ -27,7 +27,8 @@ import (
"time"
"cloud.google.com/go/profiler"
"github.com/garyburd/redigo/redis"
"github.com/gomodule/redigo/redis"
"p83.nl/go/ekster/pkg/microsub"
)

View File

@ -36,7 +36,7 @@ import (
"p83.nl/go/ekster/pkg/fetch"
"p83.nl/go/ekster/pkg/microsub"
"github.com/garyburd/redigo/redis"
"github.com/gomodule/redigo/redis"
"willnorris.com/go/microformats"
)
@ -511,6 +511,8 @@ func (b *memoryBackend) Search(query string) ([]microsub.Feed, error) {
log.Printf("Error while fetching %s: %v\n", u, err)
continue
}
defer resp.Body.Close()
fetchUrl, err := url.Parse(u)
md := microformats.Parse(resp.Body, fetchUrl)
if err != nil {
@ -567,6 +569,7 @@ func (b *memoryBackend) PreviewURL(previewURL string) (microsub.Timeline, error)
if err != nil {
return microsub.Timeline{}, fmt.Errorf("error while fetching %s: %v", previewURL, err)
}
defer resp.Body.Close()
items, err := fetch.FeedItems(&fetch2{}, previewURL, resp.Header.Get("content-type"), resp.Body)
if err != nil {
return microsub.Timeline{}, fmt.Errorf("error while fetching %s: %v", previewURL, err)

View File

@ -29,7 +29,7 @@ import (
"p83.nl/go/ekster/pkg/jf2"
"p83.nl/go/ekster/pkg/microsub"
"github.com/garyburd/redigo/redis"
"github.com/gomodule/redigo/redis"
"willnorris.com/go/microformats"
)

View File

@ -26,7 +26,7 @@ import (
"p83.nl/go/ekster/pkg/microsub"
"github.com/garyburd/redigo/redis"
"github.com/gomodule/redigo/redis"
)
type microsubHandler struct {
@ -225,18 +225,11 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if method == "mark_read" || r.PostForm.Get("method") == "mark_read" {
values = r.Form
channel := values.Get("channel")
var markAsRead []string
if uids, e := values["entry"]; e {
err := h.Backend.MarkRead(channel, uids)
if err != nil {
http.Error(w, err.Error(), 500)
return
}
markAsRead = uids
} else if uids, e := values["entry[]"]; e {
err := h.Backend.MarkRead(channel, uids)
if err != nil {
http.Error(w, err.Error(), 500)
return
}
markAsRead = uids
} else {
uids := []string{}
for k, v := range values {
@ -244,7 +237,11 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
uids = append(uids, v...)
}
}
err := h.Backend.MarkRead(channel, uids)
markAsRead = uids
}
if len(markAsRead) > 0 {
err := h.Backend.MarkRead(channel, markAsRead)
if err != nil {
http.Error(w, err.Error(), 500)
return