-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhttp.go
More file actions
32 lines (27 loc) · 739 Bytes
/
http.go
File metadata and controls
32 lines (27 loc) · 739 Bytes
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
package main
import (
"log"
"net/http"
)
func runHTTPServer() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
// log
log.Printf("http: %s %s from %s", r.Method, r.URL.Path, r.RemoteAddr)
switch r.URL.Path {
case "/200", "/ok":
w.WriteHeader(http.StatusOK)
w.Write([]byte("ok"))
case "/500", "/internal-server-error":
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte("internal server error"))
case "/403", "/forbidden":
w.WriteHeader(http.StatusForbidden)
w.Write([]byte("forbidden"))
default:
w.WriteHeader(http.StatusNotFound)
w.Write([]byte("not found"))
}
})
log.Printf("http: starting http server at %s", ":8080")
http.ListenAndServe(":8080", nil)
}