-3
handler := func(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "<html><body>Hello World!</body></html>")
}
가하고있는 func
키워드는 무엇입니까? 나는 투어 오브 투어를 통해 독서를하고 있으며, 여기서 무슨 일이 일어나고 있는지 혼란 스럽다.
편집 : 수입 목록을 추가하고 떨어져
그것은 여기 기능의 일부의 것을 기능 :
func ExampleResponseRecorder() {
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))
// Output:
// 200
// text/html; charset=utf-8
// <html><body>Hello World!</body></html>
}
import (
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"net/http/httptest"
)
참조 https://golang.org/ref/spec#FunctionLit –