|
@@ -4,19 +4,26 @@ import (
|
|
|
"fmt"
|
|
|
"html/template"
|
|
|
|
|
|
- // "io"
|
|
|
"net/http"
|
|
|
"strconv"
|
|
|
|
|
|
"github.com/gorilla/mux"
|
|
|
)
|
|
|
|
|
|
+// Struct for torrent entry in 'New torrents' list
|
|
|
+type Entry struct {
|
|
|
+ Num int
|
|
|
+ Link string
|
|
|
+}
|
|
|
+
|
|
|
+// indexHandler handels index page
|
|
|
func indexHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
data := struct {
|
|
|
User string
|
|
|
Password string
|
|
|
Title string
|
|
|
Items []string
|
|
|
+ Entrys []Entry
|
|
|
}{
|
|
|
User: "",
|
|
|
Title: "My page",
|
|
@@ -45,13 +52,14 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /*
|
|
|
- fmt.Println(data.User)
|
|
|
- fmt.Println(data.Password)
|
|
|
- */
|
|
|
+ // fmt.Println(data.User)
|
|
|
+ // fmt.Println(data.Password)
|
|
|
|
|
|
- tindexTemplate, err := template.New("").ParseFiles(INDEX_TEMPLATE, "ui\\templates\\placeholder.html")
|
|
|
+ // tindexTemplate, err := template.New("").ParseFiles(INDEX_TEMPLATE, "ui\\templates\\placeholder.html")
|
|
|
|
|
|
+ tindexTemplate, err := template.New("").ParseFiles(NewIndexTemplate, TorrentEntry, TorrentList)
|
|
|
+
|
|
|
+
|
|
|
if err != nil {
|
|
|
fmt.Println("Error in templates loading")
|
|
|
fmt.Println(err)
|
|
@@ -59,9 +67,41 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- err = tindexTemplate.ExecuteTemplate(w, "index", data)
|
|
|
+ data.Entrys = append(data.Entrys, Entry{Num: 54, Link: "/files/torrents/2torrent.torrent"})
|
|
|
+ data.Entrys = append(data.Entrys, Entry{Num: 10, Link: "/files/torrents/1torrent.torrent"})
|
|
|
+ data.Entrys = append(data.Entrys, Entry{Num: 23, Link: "/files/torrents/3torrent.torrent"})
|
|
|
+ data.Entrys = append(data.Entrys, Entry{Num: 82, Link: "/files/torrents/4torrent.torrent"})
|
|
|
+ data.Entrys = append(data.Entrys, Entry{Num: 12, Link: "/files/torrents/5torrent.torrent"})
|
|
|
+ data.Entrys = append(data.Entrys, Entry{Num: 98, Link: "/files/torrents/6torrent.torrent"})
|
|
|
+ data.Entrys = append(data.Entrys, Entry{Num: 18, Link: "/files/torrents/7torrent.torrent"})
|
|
|
+ data.Entrys = append(data.Entrys, Entry{Num: 35, Link: "/files/torrents/8torrent.torrent"})
|
|
|
+ data.Entrys = append(data.Entrys, Entry{Num: 4, Link: "/files/torrents/9torrent.torrent"})
|
|
|
+
|
|
|
+
|
|
|
+ // LastTorrents, err := dBConnector.SelectTorrents(10)
|
|
|
+ // if err != nil {
|
|
|
+ // fmt.Println(err)
|
|
|
+ // }
|
|
|
+ // for _, torrent := LastTorrents {
|
|
|
+ // torrentTopic, err := dBConnector.GetTorrentTopic(torrent.Hash)
|
|
|
+ // if err != nil {
|
|
|
+ // fmt.Println(err)
|
|
|
+ // continue
|
|
|
+ // }
|
|
|
+ // torrentEntry := Entry{
|
|
|
+ // Title: torrentTopic.Title,
|
|
|
+ // Desc: torrentTopic.Desc,
|
|
|
+ // TopicLink: torrentTopic.Link,
|
|
|
+ // Endorsments: torrent.Endors,
|
|
|
+ // TorrentLink: GenTorrentLink(torrent.Hash),
|
|
|
+ // }
|
|
|
+ // data.Entrys = append(data.Entrys, torrentEntry)
|
|
|
+ // }
|
|
|
+
|
|
|
+ err = tindexTemplate.ExecuteTemplate(w, "newindex", data)
|
|
|
if err != nil {
|
|
|
fmt.Println(err)
|
|
|
+ w.Write([]byte("Internal server error"))
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -108,7 +148,7 @@ func logInPostHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
}
|
|
|
fmt.Printf("Login error")
|
|
|
logInTemplate.Execute(w, data)
|
|
|
- //w.Write([]byte("Login error"))
|
|
|
+ // w.Write([]byte("Login error"))
|
|
|
}
|
|
|
|
|
|
}
|