-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
65 lines (56 loc) · 1.35 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
62
63
64
65
package main
import (
"flag"
"fmt"
"net"
"net/http"
"os"
"path"
"runtime"
log "github.com/sirupsen/logrus"
)
func main() {
log.SetOutput(os.Stdout)
log.SetReportCaller(true)
log.SetLevel(log.InfoLevel)
log.SetFormatter(&log.TextFormatter{
DisableLevelTruncation: true,
PadLevelText: true,
FullTimestamp: true,
CallerPrettyfier: func(f *runtime.Frame) (string, string) {
// return fmt.Sprintf("%s()", f.Function), fmt.Sprintf("%s:%d", path.Base(f.File), f.Line)
return "", fmt.Sprintf(" %s:%d", path.Base(f.File), f.Line)
},
})
// command line arguments
storePath := flag.String(
"storage",
"data",
"path to directory containing profile files",
)
listenPort := flag.String(
"port",
"8080",
"server listen port",
)
debugMode := flag.Bool(
"debug",
false,
"enable debug logs",
)
flag.Parse()
if *debugMode {
log.SetLevel(log.DebugLevel)
}
mux := http.NewServeMux()
// local file storage handlers
storage := &fileServer{directory: *storePath}
mux.HandleFunc("/", storage.handleIndex)
mux.HandleFunc("/pprof/", storage.handleFile)
mux.HandleFunc("/upload", storage.handleUpload)
mux.HandleFunc("/remove/", storage.handleRemove)
log.Infof("starting server at port %s", *listenPort)
if err := http.ListenAndServe(net.JoinHostPort("0.0.0.0", *listenPort), mux); err != nil {
log.Fatal(err)
}
}