-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
61 lines (49 loc) · 1.11 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
55
56
57
58
59
60
61
package main
import (
"encoding/json"
"errors"
"fmt"
"html/template"
"net/http"
"os"
)
var (
indexTemplate *template.Template
data []struct {
Name string
Src string
}
)
func getRoot(w http.ResponseWriter, _ *http.Request) {
err := indexTemplate.Execute(w, data)
if err != nil {
w.WriteHeader(500)
_, err := w.Write([]byte(err.Error()))
if err != nil {
return
}
}
}
func main() {
setup()
http.HandleFunc("/", getRoot)
http.Handle("/submit", http.RedirectHandler("https://github.com/derconno/shouldiresponsiblydisclose/issues", http.StatusFound))
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("./static"))))
err := http.ListenAndServe("0.0.0.0:8080", nil)
if errors.Is(err, http.ErrServerClosed) {
fmt.Println("[+] Server closed")
} else if err != nil {
fmt.Printf("[-] %s, \n", err.Error())
}
}
func setup() {
indexTemplate = template.Must(template.New("index.html").ParseFiles("templates/index.html"))
rawData, err := os.ReadFile("data.json")
if err != nil {
panic(err)
}
err = json.Unmarshal(rawData, &data)
if err != nil {
panic(err)
}
}