-
Notifications
You must be signed in to change notification settings - Fork 0
/
web.go
50 lines (42 loc) · 1.04 KB
/
web.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
// This file handles the web interface
package main
import (
"log"
"net/http"
"os"
)
func startWebInterface() {
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
html, err := os.ReadFile("web_interface.html")
if err != nil {
log.Panicln(err.Error())
}
w.Write(html)
})
http.HandleFunc("/fetch", func(w http.ResponseWriter, req *http.Request) {
if currentlyFetchingTargets {
w.Write([]byte("Fetching currently in progress."))
return
}
go startGofers(db, &config.Targets)
w.Write([]byte("Fetch process started."))
})
http.HandleFunc("/announce", func(w http.ResponseWriter, req *http.Request) {
if session != nil {
go startAnnouncers(db)
w.Write([]byte("Announcement process started."))
} else {
w.Write([]byte("Could not start announcement process: no Discord session."))
}
})
port := config.WebInterfacePort
if port == "" {
port = ":8080"
} else {
port = ":" + config.WebInterfacePort
}
err := http.ListenAndServe(port, nil)
if err != nil {
log.Println(err.Error())
}
}