-
Notifications
You must be signed in to change notification settings - Fork 0
/
haven.go
51 lines (43 loc) · 993 Bytes
/
haven.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
package main
import (
"fmt"
"flag"
"log"
"net/http"
"os"
"runtime/pprof"
"time"
)
const DEBUG bool = false
var heapprofile = flag.String("heapprofile", "", "write heap profile to file")
func dumpHeap() {
f, err := os.Create(fmt.Sprintf("haven-heap-%v.prof", time.Now()))
if err != nil {
log.Println(err)
return
}
pprof.Lookup("heap").WriteTo(f, 0)
f.Close()
}
func main() {
flag.Parse()
if *heapprofile != "" {
go func() {
c := time.Tick(10 * time.Second)
for _ = range c {
dumpHeap()
}
}()
}
notFoundHandler := NewNotFoundHandler()
fileHandler := NewFileHandler(notFoundHandler)
fetchHandler := &FetchHandler{notFoundHandler}
go fileHandler.GenerateUIDs()
http.Handle("/files/", http.StripPrefix("/files/", fileHandler))
http.Handle("/fetch/", fetchHandler)
http.Handle("/", http.FileServer(http.Dir("public")))
err := http.ListenAndServe(":9001", nil)
if err != nil {
log.Fatal(err)
}
}