-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
39 lines (31 loc) · 777 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
package main
import (
"log"
"net/http"
)
const (
addr = "0.0.0.0:80"
)
func errorHandler(w http.ResponseWriter, r *http.Request) {
log.Printf("error: %v", r.URL)
http.Error(w, "Error handler", 500)
}
func notFoundHandler(w http.ResponseWriter, r *http.Request) {
log.Printf("not found: %v", r.URL)
http.Error(w, "Not found handler", 404)
}
func okHandler(w http.ResponseWriter, r *http.Request) {
log.Printf("ok: %v", r.URL)
w.Write([]byte("ok"))
}
func main() {
server := &http.Server{Addr: addr}
http.HandleFunc("/error/", errorHandler)
http.HandleFunc("/notfound/", notFoundHandler)
http.HandleFunc("/", okHandler)
log.Printf("Listening on %v", addr)
err := server.ListenAndServe()
if err != nil {
log.Fatalf("Error starting server: %v", err)
}
}