forked from giantswarm/helloworld
/
main.go
36 lines (30 loc) · 767 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
package main
import (
"log"
"mime"
"net/http"
"os"
"os/signal"
"syscall"
)
func main() {
mime.AddExtensionType(".ico", "image/x-icon")
mime.AddExtensionType(".svg", "image/svg+xml")
fileHandler := http.FileServer(http.Dir("/content"))
http.Handle("/", loggingHandler(fileHandler))
go func() {
log.Println("Starting up at :8080")
log.Fatal(http.ListenAndServe(":8080", nil))
}()
// Handle SIGTERM.
ch := make(chan os.Signal)
signal.Notify(ch, syscall.SIGTERM)
log.Printf("Received signal '%v'. Exiting.", <-ch)
}
// HTTP Handler that adds logging to STDOUT
func loggingHandler(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
log.Println(r.Method, r.URL.Path)
h.ServeHTTP(w, r)
})
}