|
|
|
@ -14,8 +14,12 @@ import (
|
|
|
|
|
type IndexData struct {
|
|
|
|
|
Folders map[string]int
|
|
|
|
|
Mails interface{}
|
|
|
|
|
}
|
|
|
|
|
CurrentPage int
|
|
|
|
|
NextPage,PrePage string
|
|
|
|
|
NumPages map[string]template.HTML
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
const PAGE_SIZE=20
|
|
|
|
|
func main() {
|
|
|
|
|
log.Println("listen on 8080...")
|
|
|
|
|
http.HandleFunc("/", index)
|
|
|
|
@ -69,16 +73,44 @@ func list(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
authStrings := strings.Split(auth, "|")
|
|
|
|
|
|
|
|
|
|
render := new(IndexData)
|
|
|
|
|
render.CurrentPage = currentPage
|
|
|
|
|
var prePage int
|
|
|
|
|
if(currentPage-1) <=0 {
|
|
|
|
|
prePage=1
|
|
|
|
|
}else{
|
|
|
|
|
prePage=currentPage-1
|
|
|
|
|
}
|
|
|
|
|
render.PrePage = fmt.Sprintf("/list?fid=%s&page=%d",fid,prePage)
|
|
|
|
|
render.NextPage = fmt.Sprintf("/list?fid=%s&page=%d",fid,currentPage+1)
|
|
|
|
|
|
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
|
wg.Add(1)
|
|
|
|
|
go func() {
|
|
|
|
|
defer wg.Done()
|
|
|
|
|
folders :=tools.GetFolders(authStrings[0], authStrings[1], authStrings[2])
|
|
|
|
|
folders :=tools.GetFolders(authStrings[0], authStrings[1], authStrings[2],fid)
|
|
|
|
|
render.Folders = folders
|
|
|
|
|
}()
|
|
|
|
|
mails := tools.GetFolderMail(authStrings[0], authStrings[1], authStrings[2], fid,currentPage, 20)
|
|
|
|
|
mails := tools.GetFolderMail(authStrings[0], authStrings[1], authStrings[2], fid,currentPage, PAGE_SIZE)
|
|
|
|
|
render.Mails = mails
|
|
|
|
|
wg.Wait()
|
|
|
|
|
|
|
|
|
|
PageCount:=(render.Folders[fid]/PAGE_SIZE)
|
|
|
|
|
log.Println(PageCount)
|
|
|
|
|
numPages:=""
|
|
|
|
|
start:=currentPage-5
|
|
|
|
|
if start <=0 {
|
|
|
|
|
start=1
|
|
|
|
|
}
|
|
|
|
|
end:=start+11
|
|
|
|
|
|
|
|
|
|
for i:=start;i<end;i++{
|
|
|
|
|
active:=""
|
|
|
|
|
if currentPage==i{
|
|
|
|
|
active="active"
|
|
|
|
|
}
|
|
|
|
|
numPages+=fmt.Sprintf("<li class=\"page-item %s\"><a class=\"page-link\" href=\"/list?fid=%s&page=%d\">%d</a></li>",active,fid,i,i)
|
|
|
|
|
}
|
|
|
|
|
render.NumPages=map[string]template.HTML{"NumPages": template.HTML(numPages)}
|
|
|
|
|
t, _ := template.ParseFiles("./tmpl/index.html")
|
|
|
|
|
t.Execute(w, render)
|
|
|
|
|
}
|
|
|
|
|