We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 55a68aa commit 1879f55Copy full SHA for 1879f55
example/main.go
@@ -3,6 +3,7 @@ package main
3
import (
4
"context"
5
"fmt"
6
+ "io"
7
"log"
8
"net/http"
9
@@ -30,3 +31,13 @@ func main() {
30
31
fmt.Println("listening at http://localhost:8080")
32
log.Fatal(http.ListenAndServe(":8080", nil))
33
}
34
+
35
+// statusCodeHandler is useful for testing the server by returning a
36
+// specific HTTP status code.
37
+// http.Handle("/", statusCodeHandler(http.StatusInternalServerError))
38
+type statusCodeHandler int
39
40
+func (c statusCodeHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
41
+ w.WriteHeader(int(c))
42
+ io.WriteString(w, http.StatusText(int(c)))
43
+}
0 commit comments