-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.go
56 lines (46 loc) · 1.14 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
package main
import (
"flag"
"fmt"
"html/template"
"math/rand"
"net/http"
"os"
"strings"
"time"
"github.com/golang/glog"
)
var port *uint64
var tmpl *template.Template
var host *string
// Dead simple router that just does the **perform** the job
func router(w http.ResponseWriter, r *http.Request) {
switch {
case strings.Contains(r.Header.Get("Content-type"), "multipart/form-data"):
upload(w, r)
case uuidMatch.MatchString(r.URL.Path):
getFile(w, r)
default:
home(w, r)
}
}
// Route handling, logging and application serving
func main() {
// Random seed creation
rand.Seed(time.Now().Unix())
// Home template initalization
tmpl = template.Must(template.ParseFiles("./templates/index.html"))
// Flags for the leveled logging
host = flag.String("h", "0.0.0.0", "Address to serve on")
port = flag.Uint64("p", 8000, "port")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "USAGE: ./0xg0.st -p=8080 -stderrthreshold=[INFO|WARNING|FATAL] -log_dir=[string]\n")
flag.PrintDefaults()
os.Exit(1)
}
flag.Parse()
glog.Flush()
// Routing
http.HandleFunc("/", router)
http.ListenAndServe(fmt.Sprintf("%s:%d",*host,*port), nil)
}