-
Notifications
You must be signed in to change notification settings - Fork 12
/
main.go
51 lines (40 loc) · 937 Bytes
/
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
package main
import (
"flag"
"log"
"net/http"
"os"
)
var (
webAddr = flag.String("web", ":8888", "web server address")
verbose = flag.Bool("verbose", false, "enable verbose log")
accessLog = flag.Bool("access", false, "enable access log")
)
func main() {
flag.Parse()
if *verbose {
l = log.New(os.Stderr, "", log.Lmicroseconds)
}
http.HandleFunc("/gopath", gopathHandler)
http.Handle("/static/", http.FileServer(http.Dir(".")))
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if *accessLog {
log.Printf(`- %v "%s %s"`, r.RemoteAddr, r.Method, r.URL.Path)
}
if r.URL.Path == "/" {
http.ServeFile(w, r, "static/index.html")
return
}
http.NotFound(w, r)
})
logf("serving at %s", *webAddr)
if err := http.ListenAndServe(*webAddr, nil); err != nil {
log.Fatal(err)
}
}
var l *log.Logger
func logf(f string, a ...interface{}) {
if l != nil {
l.Printf(f, a...)
}
}