small cleanups
This commit is contained in:
@@ -355,7 +355,8 @@ func TestServer_Counts(t *testing.T) {
|
||||
j := []store.PostInfo{}
|
||||
err = json.Unmarshal(body, &j)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, []store.PostInfo([]store.PostInfo{store.PostInfo{URL: "https://radio-t.com/blah1", Count: 3}, store.PostInfo{URL: "https://radio-t.com/blah2", Count: 2}}), j)
|
||||
assert.Equal(t, []store.PostInfo([]store.PostInfo{{URL: "https://radio-t.com/blah1", Count: 3},
|
||||
{URL: "https://radio-t.com/blah2", Count: 2}}), j)
|
||||
}
|
||||
|
||||
func TestServer_List(t *testing.T) {
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
cache "github.com/patrickmn/go-cache"
|
||||
"github.com/patrickmn/go-cache"
|
||||
)
|
||||
|
||||
// LoadingCache defines interface for caching
|
||||
|
||||
@@ -20,12 +20,12 @@ func SendErrorJSON(w http.ResponseWriter, r *http.Request, code int, err error,
|
||||
|
||||
func logDetails(r *http.Request, code int, err error, details string) {
|
||||
uinfoStr := ""
|
||||
if user, е := GetUserInfo(r); е == nil {
|
||||
if user, e := GetUserInfo(r); e == nil {
|
||||
uinfoStr = user.Name + "/" + user.ID + " - "
|
||||
}
|
||||
|
||||
q := r.URL.String()
|
||||
if qun, е := url.QueryUnescape(q); е == nil {
|
||||
if qun, e := url.QueryUnescape(q); e == nil {
|
||||
q = qun
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ type BlockedUser struct {
|
||||
}
|
||||
|
||||
// PrepareUntrusted preprocess comment received from untrusted source by clearing all
|
||||
// autogen fields and reset everyting users not supposed to provide
|
||||
// autogen fields and reset everything users not supposed to provide
|
||||
func (c *Comment) PrepareUntrusted() {
|
||||
c.ID = "" // don't allow user to define ID, force auto-gen
|
||||
c.Timestamp = time.Time{} // reset time, force auto-gen
|
||||
@@ -115,9 +115,3 @@ func (c *Comment) SetDeleted() {
|
||||
c.Edit = nil
|
||||
c.Deleted = true
|
||||
}
|
||||
|
||||
// NotifUser holds id and destination for notifiable user
|
||||
type NotifUser struct {
|
||||
ID string `json:"id"`
|
||||
Destination string `json:"destination"`
|
||||
}
|
||||
|
||||
@@ -136,13 +136,13 @@ func TestService_Counts(t *testing.T) {
|
||||
svc := Service{Interface: b}
|
||||
res, err := svc.Counts("radio-t", []string{"https://radio-t.com/2"})
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, []PostInfo{PostInfo{URL: "https://radio-t.com/2", Count: 1}}, res)
|
||||
assert.Equal(t, []PostInfo{{URL: "https://radio-t.com/2", Count: 1}}, res)
|
||||
|
||||
res, err = svc.Counts("radio-t", []string{"https://radio-t.com", "https://radio-t.com/2", "blah"})
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, []PostInfo{
|
||||
PostInfo{URL: "https://radio-t.com", Count: 2},
|
||||
PostInfo{URL: "https://radio-t.com/2", Count: 1},
|
||||
PostInfo{URL: "blah", Count: 0},
|
||||
{URL: "https://radio-t.com", Count: 2},
|
||||
{URL: "https://radio-t.com/2", Count: 1},
|
||||
{URL: "blah", Count: 0},
|
||||
}, res)
|
||||
}
|
||||
|
||||
@@ -33,13 +33,6 @@ type Admin interface {
|
||||
Blocked(siteID string) ([]BlockedUser, error) // get list of blocked users
|
||||
}
|
||||
|
||||
// Notifier defines all store ops to store/retrieve notification info for users
|
||||
type Notifier interface {
|
||||
Set(locator Locator, user NotifUser, status bool) error // subscribe / unsubscribe user to locator updates
|
||||
Status(locator Locator, userID string) bool // get subscription status for user & locator
|
||||
List(locator Locator) ([]NotifUser, error) // list all subscribed users
|
||||
}
|
||||
|
||||
func sortComments(comments []Comment, sortFld string) []Comment {
|
||||
sort.Slice(comments, func(i, j int) bool {
|
||||
switch sortFld {
|
||||
|
||||
Reference in New Issue
Block a user