Exemplo n.º 1
0
func LogPanicHandler(l app.Logger) func(w http.ResponseWriter, r *http.Request, p interface{}) {
	return func(w http.ResponseWriter, r *http.Request, p interface{}) {
		l.Output(2, fmt.Sprintf("Error:panic in http handler -%s", p))
		Decorate(func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) (interface{}, error) {
			return nil, Err{500, "Internal ERROR"}
		}, Log(l), V1)(w, r, nil)

	}
}
Exemplo n.º 2
0
func Log(Logger app.Logger) Decorator {
	return func(f APIHandler) APIHandler {
		return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) (interface{}, error) {
			start := time.Now()
			response, err := f(w, r, ps)
			elapsed := time.Since(start)
			status := 200
			if e, ok := err.(Err); ok {
				status = e.Code
			}

			Logger.Output(2, fmt.Sprintf("%d %s %s (%s) %s", status, r.Method, r.URL.RequestURI(), r.RemoteAddr, elapsed))

			return response, err
		}
	}
}