blob: e94bb029c87d2879202828da3eb0edbd2d048785 (
plain) (
blame)
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
|
package main
import (
"log"
"net/http"
"os"
"os/signal"
"time"
)
func main() {
logChan := make(chan struct{})
initLogging(logChan)
sigC := make(chan os.Signal, 1)
signal.Notify(sigC, os.Interrupt)
go func(chan<- struct{}) {
for range sigC {
log.Printf("^C Caught. Shutting down ...")
logChan <- struct{}{}
os.Exit(1)
}
}(logChan)
mux := http.NewServeMux()
mux.HandleFunc("/", mainHandler)
mux.HandleFunc("/favicon.ico", func(w http.ResponseWriter, r *http.Request) {
http.Error(w, "404 Not Found", http.StatusNotFound)
})
server := &http.Server{
Addr: ":9999",
Handler: ipMiddleware(mux),
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
}
log.Println("Starting up")
log.Printf("Listening on %s\n", server.Addr)
log.Fatalf("%s", server.ListenAndServe().Error())
}
|