27 lines
501 B
Go
27 lines
501 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"io"
|
||
|
"io/ioutil"
|
||
|
"net/http"
|
||
|
"net/http/httptest"
|
||
|
)
|
||
|
|
||
|
func main() {
|
||
|
handler := func(w http.ResponseWriter, r *http.Request) {
|
||
|
io.WriteString(w, "<html><body>Hello World!</body></html>")
|
||
|
}
|
||
|
|
||
|
req := httptest.NewRequest("GET", "http://example.com/foo", nil)
|
||
|
w := httptest.NewRecorder()
|
||
|
handler(w, req)
|
||
|
|
||
|
resp := w.Result()
|
||
|
body, _ := ioutil.ReadAll(resp.Body)
|
||
|
|
||
|
fmt.Println(resp.StatusCode)
|
||
|
fmt.Println(resp.Header.Get("Content-Type"))
|
||
|
fmt.Println(string(body))
|
||
|
}
|