forked from AmarnathCJD/CloudTorrent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
54 lines (49 loc) · 1.47 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"fmt"
"html/template"
"log"
"net/http"
"os"
"path/filepath"
)
var (
Wd, _ = os.Getwd()
Root = filepath.Join(Wd, "downloads")
Port = GetOutboundPort()
)
func main() {
fmt.Print("Starting server...")
HTMLServe()
go streamTorrentUpdate()
if err := http.ListenAndServe(Port, nil); err != nil {
log.Fatal("ListenAndServe: ", err)
}
}
func HTMLServe() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "./static/index.html")
})
http.HandleFunc("/downloads/", func(w http.ResponseWriter, r *http.Request) {
template := template.Must(template.ParseFiles("./static/downloads.html"))
template.Execute(w, nil)
})
http.HandleFunc("/stream/", func(w http.ResponseWriter, r *http.Request) {
template := template.Must(template.ParseFiles("./static/player.html"))
template.Execute(w, nil)
})
http.HandleFunc("/search/", func(w http.ResponseWriter, r *http.Request) {
template := template.Must(template.ParseFiles("./static/search.html"))
template.Execute(w, nil)
})
// static files
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("./static"))))
}
func init() {
log.SetFlags(log.LstdFlags | log.Lshortfile)
http.HandleFunc("/test/", func(w http.ResponseWriter, r *http.Request) {
template := template.Must(template.ParseFiles("./assets/test.html"))
template.Execute(w, nil)
})
http.Handle("/assets/", http.StripPrefix("/assets/", http.FileServer(http.Dir("./assets"))))
}