Example #1
0
func (t *Townclient) dumpRequest(req *http.Request, name string) {
	if DUMP == 1 {
		dump1, err := httputil.DumpRequestOut(req, true)
		if err != nil {
			log.Critical("dump of %v request failed", name)
		}
		ioutil.WriteFile(name, dump1, 0777)
	}
}
Example #2
0
func (t *Townclient) dumpResponse(resp *http.Response, name string) {
	if DUMP == 1 {
		dump, err := httputil.DumpResponse(resp, true)
		if err != nil {
			log.Critical("log failed for get Request")
		}
		ioutil.WriteFile(name, dump, 0777)
	}
}
Example #3
0
package middleware

import (
	"net/http"

	"github.com/dvirsky/go-pylog/logging"

	"github.com/EverythingMe/vertex"
)

// AutoRecover is a middleware that recovers automatically from panics inside request handlers
var AutoRecover = vertex.MiddlewareFunc(func(w http.ResponseWriter, r *vertex.Request, next vertex.HandlerFunc) (ret interface{}, err error) {

	defer func() {

		e := recover()
		if e != nil {
			logging.Critical("Caught panic: %v", e)

			err = vertex.NewErrorf("PANIC handling %s: %s", r.URL.Path, e)
			return
		}
	}()

	return next(w, r)

})