title: Extending GoLang's http.ResponseWriter functionality to pre/post process responses
body: <p>I am trying to write a simple http MiddleWare handler that will process an http response.  Unfortunately, it does not work and I cannot figure out what mistake I am making.  Any/all help is appreciated!</p>
  
  <p>I am using Go Gorilla mux router 
  Here are illustrative parts of the code:</p>
  
  <pre><code>import (
      "fmt"
      "log"
      "github.com/gorilla/mux"
  )
  :
  func Start() {
      router := mux.NewRouter()
      router.HandleFunc("/", myHandler)
      :
      log.Fatal(http.ListenAndServe(":8088", Middleware(router)))
  }
  
  func myHandler(w http.ResponseWriter, r *http.Request) {
      fmt.Fprintln(w, "myHandler called")
  }
  func Middleware(h http.Handler) http.Handler {
      return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
          neww := NewProcessor(w)
          h.ServeHTTP(neww, r)
      })
  }
  
  type Processor struct {
      http.ResponseWriter
  }
  func (r *Processor) Write(b []byte) (int, error) {
      fmt.Printf("******* Processor writing...")
      log.Print(string(b)) // log it out
      return r.Write(b)    // pass it to the original ResponseWriter
  }
  func NewProcessor(w http.ResponseWriter) http.ResponseWriter {
      fmt.Printf("******* Creating new Processor...")
      return &amp;Processor{ResponseWriter: w}
  }
  </code></pre>
  
  <p>The output I get is listed below (extra logging text omitted for clarity):</p>
  
  <pre><code>******* Creating new Processor 
  myHandler called
  </code></pre>
  
  <p>However, notice the message "******* Processor writing..." was not displayed, suggesting that the "Write" function did not get called.</p>
  
  <p>What changes need to be made to allow the "Write" function to be called?</p>