Alex

HTTP and Networking in Go (Video 15)

type Handler interface {
  ServeHTTP(http.ResponseWriter, *http.Request)
}
type HandlerFunc func(ResponseWriter, *Request)

// This is a method declaration on a function type
func (f HandlerFunc) ServeHTTP(w ResponseWriter, r *Request) {
  f(w, r)
}

// Then we can define a function that conforms to that interface without 
// requiring explicit implementation of ServeHTTPz§
func handler(w http.ResponseWriter, r *http.Request) {
  fmt.Fprintf(w, "Hello, world")
}
var form = `
<h1>Todo #</h1>
<div></div>