首先,我仍然不清楚如何构建这个问题,但我无法理解,有人可以帮助我理解这一点。如果我重命名“serveHTTP”或没有该方法,为什么下面的代码会出错。
prog.go:17: cannot use &status (type *statusHandler) as type http.Handler in argument to httptest.NewServer:
*statusHandler does not implement http.Handler (missing ServeHTTP method)
[process exited with non-zero status]
对于下面的代码
type statusHandler int
func (s *statusHandler) aServeHTTP(w http.ResponseWriter, r *http.Request) {
log.Println(" inside status handler serve http")
}
func main() {
status := statusHandler(400)
s := httptest.NewServer(&status)
log.Println("value of s is %d", s)
defer s.Close()
}
http://play.golang.org/p/QZIrWALAm_
婷婷同学_
相关分类