diff --git a/admin.go b/admin.go index fc675b5..2e00363 100644 --- a/admin.go +++ b/admin.go @@ -18,7 +18,7 @@ func deleteHandler(w http.ResponseWriter, r *http.Request) { var titles []string var isNew bool - ids:= strings.Split(r.URL.Path[len("/delete/"):], "/") + ids := strings.Split(r.URL.Path[len("/delete/"):], "/") for _, idStr := range ids { if idStr == "" { continue @@ -40,12 +40,12 @@ func deleteHandler(w http.ResponseWriter, r *http.Request) { os.RemoveAll(book.Path) db.RemoveBook(id) - if ! book.Active { + if !book.Active { isNew = true } titles = append(titles, book.Title) } - sess.Notify("Removed books!", "The books "+ strings.Join(titles, ", ") +" are completly removed", "success") + sess.Notify("Removed books!", "The books "+strings.Join(titles, ", ")+" are completly removed", "success") sess.Save(w, r) if isNew { http.Redirect(w, r, "/new/", 307) @@ -127,9 +127,9 @@ func saveHandler(w http.ResponseWriter, r *http.Request) { } type newBook struct { - TitleFound int + TitleFound int AuthorFound int - B Book + B Book } type newData struct { S Status @@ -156,8 +156,8 @@ func newHandler(w http.ResponseWriter, r *http.Request) { data.Books = make([]newBook, num) for i, b := range res { data.Books[i].B = b - _, data.Books[i].TitleFound, _ = db.GetBooks(buildQuery("title:" + b.Title), 1) - _, data.Books[i].AuthorFound, _ = db.GetBooks(buildQuery("author:" + strings.Join(b.Author, " author:")), 1) + _, data.Books[i].TitleFound, _ = db.GetBooks(buildQuery("title:"+b.Title), 1) + _, data.Books[i].AuthorFound, _ = db.GetBooks(buildQuery("author:"+strings.Join(b.Author, " author:")), 1) } loadTemplate(w, "new", data) } @@ -197,7 +197,7 @@ func storeHandler(w http.ResponseWriter, r *http.Request) { book := books[0] title := book.Title - path := ValidFileName(BOOKS_PATH + title[:1], title, ".epub") + path := ValidFileName(BOOKS_PATH+title[:1], title, ".epub") oldPath := book.Path os.Mkdir(BOOKS_PATH+title[:1], os.ModePerm) @@ -206,7 +206,7 @@ func storeHandler(w http.ResponseWriter, r *http.Request) { db.UpdateBook(id, bson.M{"active": true, "path": path}) titles = append(titles, book.Title) } - sess.Notify("Store books!", "The books '"+ strings.Join(titles, ", ") +"' are stored for public download", "success") + sess.Notify("Store books!", "The books '"+strings.Join(titles, ", ")+"' are stored for public download", "success") sess.Save(w, r) http.Redirect(w, r, "/new/", 307) } diff --git a/database.go b/database.go index f6a732b..0756c30 100644 --- a/database.go +++ b/database.go @@ -9,7 +9,6 @@ import ( var db *DB - type Book struct { Id string `bson:"_id"` Title string @@ -36,8 +35,8 @@ type Book struct { type DB struct { session *mgo.Session - books *mgo.Collection - user *mgo.Collection + books *mgo.Collection + user *mgo.Collection } func initDB() *DB { @@ -120,7 +119,7 @@ func (d *DB) GetBooks(query bson.M, r ...int) (books []Book, num int, err error) /* Returns: list of books, number found and err */ -func (d *DB) GetNewBooks()(books []Book, num int, err error) { +func (d *DB) GetNewBooks() (books []Book, num int, err error) { var q *mgo.Query q = d.books.Find(bson.M{"$nor": []bson.M{{"active": true}}}).Sort("-_id") num, err = q.Count() diff --git a/reader.go b/reader.go index 71884a7..ebf8acf 100644 --- a/reader.go +++ b/reader.go @@ -125,7 +125,7 @@ func readHandler(w http.ResponseWriter, r *http.Request) { var data readData data.Book = books[0] - if ! data.Book.Active { + if !data.Book.Active { sess := GetSession(r) if sess.User == "" { http.NotFound(w, r) @@ -158,7 +158,7 @@ func contentHandler(w http.ResponseWriter, r *http.Request) { return } book := books[0] - if ! book.Active { + if !book.Active { sess := GetSession(r) if sess.User == "" { http.NotFound(w, r) diff --git a/upload.go b/upload.go index 1540cb6..214927b 100644 --- a/upload.go +++ b/upload.go @@ -76,7 +76,7 @@ func storeImg(img []byte, title, extension string) (string, string) { resize := append(strings.Split(RESIZE_CMD, " "), imgPath, imgPath) cmd := exec.Command(resize[0], resize[1:]...) cmd.Run() - imgPathSmall := ValidFileName(folder, title, "_small" + extension) + imgPathSmall := ValidFileName(folder, title, "_small"+extension) resize = append(strings.Split(RESIZE_THUMB_CMD, " "), imgPath, imgPathSmall) cmd = exec.Command(resize[0], resize[1:]...) cmd.Run()