code: func handlerJSON(f failure, handler jsonAPI) http.Handler {
  	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  		//log.Printf("%s", r.URL)
  		if r.Header.Get("Content-Type") != contentType {
  			f.Fail(fmt.Errorf("invalid content type: %q", r.Header.Get("Content-Type")))
  			return
  		}
  		defer r.Body.Close()
  		out := handler(r)
  		w.Header().Set("Content-Type", contentType)
  		j := json.NewEncoder(w)
  		if err := j.Encode(out); err != nil {
  			f.Fail(err)
  		}
  	})
  }
docs: // handlerJSON converts a jsonAPI http handler to a proper http.Handler.