2020-03-19 13:23:32 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
handler := func(w http.ResponseWriter, r *http.Request) {
|
2020-03-19 13:28:29 +00:00
|
|
|
_, _ = io.WriteString(w, "<html><body>Hello World!</body></html>")
|
2020-03-19 13:23:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
req := httptest.NewRequest("GET", "http://example.com/foo", nil)
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
handler(w, req)
|
|
|
|
|
|
|
|
resp := w.Result()
|
2024-06-05 17:36:34 +00:00
|
|
|
body, _ := io.ReadAll(resp.Body)
|
2020-03-19 13:23:32 +00:00
|
|
|
|
|
|
|
fmt.Println(resp.StatusCode)
|
|
|
|
fmt.Println(resp.Header.Get("Content-Type"))
|
|
|
|
fmt.Println(string(body))
|
|
|
|
}
|