Run go fmt
This commit is contained in:
parent
d924b577d1
commit
9f1204db35
7 changed files with 24 additions and 26 deletions
|
@ -1,10 +1,10 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
|
||||||
"labix.org/v2/mgo"
|
"labix.org/v2/mgo"
|
||||||
"labix.org/v2/mgo/bson"
|
"labix.org/v2/mgo/bson"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -54,11 +54,11 @@ func searchHandler(coll *mgo.Collection) func(http.ResponseWriter, *http.Request
|
||||||
data.Search = req
|
data.Search = req
|
||||||
data.Found = len(res)
|
data.Found = len(res)
|
||||||
if len(res) > ITEMS_PAGE*(page+1) {
|
if len(res) > ITEMS_PAGE*(page+1) {
|
||||||
data.Books = res[ITEMS_PAGE*page:ITEMS_PAGE*(page+1)]
|
data.Books = res[ITEMS_PAGE*page : ITEMS_PAGE*(page+1)]
|
||||||
} else {
|
} else {
|
||||||
data.Books = res[ITEMS_PAGE*page:]
|
data.Books = res[ITEMS_PAGE*page:]
|
||||||
}
|
}
|
||||||
data.Page = page+1
|
data.Page = page + 1
|
||||||
if len(res) > (page+1)*ITEMS_PAGE {
|
if len(res) > (page+1)*ITEMS_PAGE {
|
||||||
data.Next = "/search/?q=" + req + "&p=" + strconv.Itoa(page+1)
|
data.Next = "/search/?q=" + req + "&p=" + strconv.Itoa(page+1)
|
||||||
}
|
}
|
||||||
|
|
14
template.go
14
template.go
|
@ -11,13 +11,13 @@ const (
|
||||||
|
|
||||||
func loadTemplate(w http.ResponseWriter, tmpl string, data interface{}) {
|
func loadTemplate(w http.ResponseWriter, tmpl string, data interface{}) {
|
||||||
// TODO: when finish devel conver to global:
|
// TODO: when finish devel conver to global:
|
||||||
var templates = template.Must(template.ParseFiles(TEMPLATE_DIR + "header.html",
|
var templates = template.Must(template.ParseFiles(TEMPLATE_DIR+"header.html",
|
||||||
TEMPLATE_DIR + "footer.html",
|
TEMPLATE_DIR+"footer.html",
|
||||||
TEMPLATE_DIR + "index.html",
|
TEMPLATE_DIR+"index.html",
|
||||||
TEMPLATE_DIR + "about.html",
|
TEMPLATE_DIR+"about.html",
|
||||||
TEMPLATE_DIR + "book.html",
|
TEMPLATE_DIR+"book.html",
|
||||||
TEMPLATE_DIR + "search.html",
|
TEMPLATE_DIR+"search.html",
|
||||||
TEMPLATE_DIR + "upload.html"))
|
TEMPLATE_DIR+"upload.html"))
|
||||||
|
|
||||||
err := templates.ExecuteTemplate(w, tmpl+".html", data)
|
err := templates.ExecuteTemplate(w, tmpl+".html", data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -24,13 +24,11 @@ func bookHandler(coll *mgo.Collection) func(http.ResponseWriter, *http.Request)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func fileHandler(path string) {
|
func fileHandler(path string) {
|
||||||
h := http.FileServer(http.Dir(path[1:]))
|
h := http.FileServer(http.Dir(path[1:]))
|
||||||
http.Handle(path, http.StripPrefix(path, h))
|
http.Handle(path, http.StripPrefix(path, h))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type indexData struct {
|
type indexData struct {
|
||||||
Books []Book
|
Books []Book
|
||||||
Count int
|
Count int
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"labix.org/v2/mgo"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"labix.org/v2/mgo"
|
|
||||||
//"labix.org/v2/mgo/bson"
|
//"labix.org/v2/mgo/bson"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
|
@ -118,7 +118,7 @@ func store(coll *mgo.Collection, path string) {
|
||||||
book.Keywords = keywords(book)
|
book.Keywords = keywords(book)
|
||||||
coll.Insert(book)
|
coll.Insert(book)
|
||||||
|
|
||||||
os.Mkdir(PATH + path[:1], os.ModePerm)
|
os.Mkdir(PATH+path[:1], os.ModePerm)
|
||||||
cmd := exec.Command("mv", NEW_PATH+path, book.Path)
|
cmd := exec.Command("mv", NEW_PATH+path, book.Path)
|
||||||
cmd.Run()
|
cmd.Run()
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue