small cleanups

This commit is contained in:
Umputun
2018-03-22 13:11:17 -05:00
parent 641cd28548
commit 4138a5f05a
6 changed files with 10 additions and 22 deletions
+2 -1
View File
@@ -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
View File
@@ -6,7 +6,7 @@ import (
"strings"
"time"
cache "github.com/patrickmn/go-cache"
"github.com/patrickmn/go-cache"
)
// LoadingCache defines interface for caching
+2 -2
View File
@@ -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
}
+1 -7
View File
@@ -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"`
}
+4 -4
View File
@@ -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)
}
-7
View File
@@ -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 {