code cleanup

This commit is contained in:
Nazar Kanaev 2020-07-24 16:39:12 +01:00
parent c04f54619b
commit b223233318
9 changed files with 112 additions and 184 deletions

70
main.go
View File

@ -1,80 +1,10 @@
package main package main
import ( import (
//"github.com/nkanaev/yarr/storage"
//"github.com/nkanaev/yarr/worker"
"github.com/nkanaev/yarr/server" "github.com/nkanaev/yarr/server"
//"log"
) )
func main() { func main() {
/*
store, err := storage.New()
if err != nil {
log.Fatal(err)
}
log.Print(store)
*/
/*
folder := store.CreateFolder("foo")
store.RenameFolder(folder.Id, "bar")
store.ToggleFolderExpanded(folder.Id, false)
log.Print(store.ListFolders())
*/
/*
feed := store.CreateFeed(
"title", "description", "link", "feedlink", "icon", 1)
store.RenameFeed(feed.Id, "newtitle")
log.Print(store.ListFeeds())
*/
/*;
items := make([]storage.Item, 3, 3)
items = append(items, storage.Item{
Id: "id",
FeedId: 0,
Title: "title",
Link: "link",
Description: "description",
Content: "content",
Author: "author",
Date: 1,
DateUpdated: 1,
Status: storage.UNREAD,
Image: "image",
})
items = append(items, storage.Item{
Id: "id2",
FeedId: 0,
Title: "title",
Link: "link",
Description: "description",
Content: "content",
Author: "author",
Date: 1,
DateUpdated: 50,
Status: storage.UNREAD,
Image: "image",
})
items = append(items, storage.Item{
Id: "id",
FeedId: 0,
Title: "title",
Link: "link",
Description: "description",
Content: "content",
Author: "author",
Date: 1,
DateUpdated: 100,
Status: storage.UNREAD,
Image: "image",
})
log.Print(store.CreateItems(items))
log.Print(store.ListItems())
*/
/*
log.Print(worker.FindFeeds("https://horriblesubs.info/"))
log.Print(worker.FindFeeds("http://daringfireball.net/"))
*/
srv := server.New() srv := server.New()
srv.ListenAndServe() srv.ListenAndServe()
} }

View File

@ -1,9 +1,9 @@
package server package server
import ( import (
"net/url"
"net/http"
"github.com/PuerkitoBio/goquery" "github.com/PuerkitoBio/goquery"
"net/http"
"net/url"
) )
type FeedSource struct { type FeedSource struct {
@ -13,7 +13,6 @@ type FeedSource struct {
const feedLinks = `link[type='application/rss+xml'],link[type='application/atom+xml']` const feedLinks = `link[type='application/rss+xml'],link[type='application/atom+xml']`
func FindFeeds(r *http.Response) ([]FeedSource, error) { func FindFeeds(r *http.Response) ([]FeedSource, error) {
sources := make([]FeedSource, 0, 0) sources := make([]FeedSource, 0, 0)
doc, err := goquery.NewDocumentFromResponse(r) doc, err := goquery.NewDocumentFromResponse(r)

View File

@ -1,23 +1,23 @@
package server package server
import ( import (
"github.com/nkanaev/yarr/storage"
"github.com/mmcdole/gofeed"
"net/http"
"html/template"
"encoding/json" "encoding/json"
"encoding/xml" "encoding/xml"
"os" "fmt"
"log" "github.com/mmcdole/gofeed"
"github.com/nkanaev/yarr/storage"
"html"
"html/template"
"io" "io"
"io/ioutil"
"log"
"math"
"mime" "mime"
"strings" "net/http"
"os"
"path/filepath" "path/filepath"
"strconv" "strconv"
"math" "strings"
"html"
"fmt"
"io/ioutil"
) )
func IndexHandler(rw http.ResponseWriter, req *http.Request) { func IndexHandler(rw http.ResponseWriter, req *http.Request) {
@ -78,7 +78,6 @@ func FolderListHandler(rw http.ResponseWriter, req *http.Request) {
} }
} }
type UpdateFolder struct { type UpdateFolder struct {
Title *string `json:"title,omitempty"` Title *string `json:"title,omitempty"`
IsExpanded *bool `json:"is_expanded,omitempty"` IsExpanded *bool `json:"is_expanded,omitempty"`

View File

@ -1,12 +1,12 @@
package server package server
import ( import (
"encoding/json"
"context" "context"
"regexp" "encoding/json"
"net/http"
"github.com/nkanaev/yarr/storage" "github.com/nkanaev/yarr/storage"
"log" "log"
"net/http"
"regexp"
) )
type Route struct { type Route struct {

View File

@ -1,11 +1,11 @@
package storage package storage
import ( import (
"fmt"
"time"
"strings"
"encoding/json" "encoding/json"
"fmt"
"golang.org/x/net/html" "golang.org/x/net/html"
"strings"
"time"
) )
type ItemStatus int type ItemStatus int

View File

@ -1,10 +1,10 @@
package storage package storage
import ( import (
"os"
"log"
"database/sql" "database/sql"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"log"
"os"
) )
var initQuery string = ` var initQuery string = `