mirror of
https://github.com/nkanaev/yarr.git
synced 2025-05-24 00:33:14 +00:00
go fmt
This commit is contained in:
parent
f71792d6a5
commit
2a4d974965
@ -192,23 +192,23 @@ func TestAtomLinkInID(t *testing.T) {
|
|||||||
have := feed.Items
|
have := feed.Items
|
||||||
want := []Item{
|
want := []Item{
|
||||||
Item{
|
Item{
|
||||||
GUID: "https://example.com/posts/1::2003-12-13T09:17:51",
|
GUID: "https://example.com/posts/1::2003-12-13T09:17:51",
|
||||||
Date: time.Date(2003, time.December, 13, 9, 17, 51, 0, time.UTC),
|
Date: time.Date(2003, time.December, 13, 9, 17, 51, 0, time.UTC),
|
||||||
URL: "https://example.com/posts/1",
|
URL: "https://example.com/posts/1",
|
||||||
Title: "one updated",
|
Title: "one updated",
|
||||||
},
|
},
|
||||||
Item{
|
Item{
|
||||||
GUID: "urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6",
|
GUID: "urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6",
|
||||||
Date: time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC), URL: "",
|
Date: time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC), URL: "",
|
||||||
Title: "two",
|
Title: "two",
|
||||||
},
|
},
|
||||||
Item{
|
Item{
|
||||||
GUID: "https://example.com/posts/1::",
|
GUID: "https://example.com/posts/1::",
|
||||||
Date: time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC),
|
Date: time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC),
|
||||||
URL: "https://example.com/posts/1",
|
URL: "https://example.com/posts/1",
|
||||||
Title: "one",
|
Title: "one",
|
||||||
Content: "",
|
Content: "",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(want, have) {
|
if !reflect.DeepEqual(want, have) {
|
||||||
t.Fatalf("\nwant: %#v\nhave: %#v\n", want, have)
|
t.Fatalf("\nwant: %#v\nhave: %#v\n", want, have)
|
||||||
|
@ -51,12 +51,12 @@ func (m *Middleware) Handler(c *router.Context) {
|
|||||||
c.HTML(http.StatusOK, assets.Template("login.html"), map[string]interface{}{
|
c.HTML(http.StatusOK, assets.Template("login.html"), map[string]interface{}{
|
||||||
"username": username,
|
"username": username,
|
||||||
"error": "Invalid username/password",
|
"error": "Invalid username/password",
|
||||||
"settings": m.DB.GetSettings(),
|
"settings": m.DB.GetSettings(),
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c.HTML(http.StatusOK, assets.Template("login.html"), map[string]interface{}{
|
c.HTML(http.StatusOK, assets.Template("login.html"), map[string]interface{}{
|
||||||
"settings": m.DB.GetSettings(),
|
"settings": m.DB.GetSettings(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ func (s *Server) handler() http.Handler {
|
|||||||
Username: s.Username,
|
Username: s.Username,
|
||||||
Password: s.Password,
|
Password: s.Password,
|
||||||
Public: []string{"/static", "/fever"},
|
Public: []string{"/static", "/fever"},
|
||||||
DB: s.db,
|
DB: s.db,
|
||||||
}
|
}
|
||||||
r.Use(a.Handler)
|
r.Use(a.Handler)
|
||||||
}
|
}
|
||||||
|
@ -79,22 +79,21 @@ type MarkFilter struct {
|
|||||||
type ItemList []Item
|
type ItemList []Item
|
||||||
|
|
||||||
func (list ItemList) Len() int {
|
func (list ItemList) Len() int {
|
||||||
return len(list)
|
return len(list)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (list ItemList) SortKey(i int) string {
|
func (list ItemList) SortKey(i int) string {
|
||||||
return list[i].Date.Format(time.RFC3339) + "::" + list[i].GUID
|
return list[i].Date.Format(time.RFC3339) + "::" + list[i].GUID
|
||||||
}
|
}
|
||||||
|
|
||||||
func (list ItemList) Less(i, j int) bool {
|
func (list ItemList) Less(i, j int) bool {
|
||||||
return list.SortKey(i) < list.SortKey(j)
|
return list.SortKey(i) < list.SortKey(j)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (list ItemList) Swap(i, j int) {
|
func (list ItemList) Swap(i, j int) {
|
||||||
list[i], list[j] = list[j], list[i]
|
list[i], list[j] = list[j], list[i]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (s *Storage) CreateItems(items []Item) bool {
|
func (s *Storage) CreateItems(items []Item) bool {
|
||||||
tx, err := s.db.Begin()
|
tx, err := s.db.Begin()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -104,8 +103,8 @@ func (s *Storage) CreateItems(items []Item) bool {
|
|||||||
|
|
||||||
now := time.Now().UTC()
|
now := time.Now().UTC()
|
||||||
|
|
||||||
itemsSorted := ItemList(items)
|
itemsSorted := ItemList(items)
|
||||||
sort.Sort(itemsSorted)
|
sort.Sort(itemsSorted)
|
||||||
|
|
||||||
for _, item := range itemsSorted {
|
for _, item := range itemsSorted {
|
||||||
_, err = tx.Exec(`
|
_, err = tx.Exec(`
|
||||||
|
@ -16,16 +16,16 @@ var migrations = []func(*sql.Tx) error{
|
|||||||
m06_fill_missing_dates,
|
m06_fill_missing_dates,
|
||||||
m07_add_feed_size,
|
m07_add_feed_size,
|
||||||
m08_normalize_datetime,
|
m08_normalize_datetime,
|
||||||
m09_change_item_index,
|
m09_change_item_index,
|
||||||
}
|
}
|
||||||
|
|
||||||
var maxVersion = int64(len(migrations))
|
var maxVersion = int64(len(migrations))
|
||||||
|
|
||||||
func migrate(db *sql.DB) error {
|
func migrate(db *sql.DB) error {
|
||||||
var version int64
|
var version int64
|
||||||
if err := db.QueryRow("pragma user_version").Scan(&version); err != nil {
|
if err := db.QueryRow("pragma user_version").Scan(&version); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if version >= maxVersion {
|
if version >= maxVersion {
|
||||||
return nil
|
return nil
|
||||||
|
@ -14,10 +14,10 @@ type Storage struct {
|
|||||||
|
|
||||||
func New(path string) (*Storage, error) {
|
func New(path string) (*Storage, error) {
|
||||||
if pos := strings.IndexRune(path, '?'); pos == -1 {
|
if pos := strings.IndexRune(path, '?'); pos == -1 {
|
||||||
params := "_journal=WAL&_sync=NORMAL&_busy_timeout=5000&cache=shared"
|
params := "_journal=WAL&_sync=NORMAL&_busy_timeout=5000&cache=shared"
|
||||||
log.Printf("opening db with params: %s", params)
|
log.Printf("opening db with params: %s", params)
|
||||||
path = path + "?" + params
|
path = path + "?" + params
|
||||||
}
|
}
|
||||||
|
|
||||||
db, err := sql.Open("sqlite3", path)
|
db, err := sql.Open("sqlite3", path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user