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
package main
import (
"fmt"
"log"
"net/http"
"path/filepath"
"html/template"
"os"
)
func main() {
http.HandleFunc("/", rootHandler)
log.Println("listening on :7368 tbh")
err := http.ListenAndServe(":7368", nil)
if err != nil {
log.Fatal(err)
}
}
func rootHandler(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/" {
r.URL.Path = "index.html"
}
t := filepath.Join("bin", filepath.Clean(r.URL.Path))
_, err := os.Stat(t)
if err != nil {
fmt.Fprintf(w, err.Error())
return
}
tmpl, err := template.ParseFiles(t)
if err != nil {
fmt.Fprintf(w, err.Error())
return
}
err = tmpl.ExecuteTemplate(w, "wat", nil)
if err != nil {
fmt.Fprintf(w, err.Error())
}
}