Beispiel #1
0
func recovery(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
	defer recoverWith(func(err error) {
		log := logger.New("ns=ccron-api").At("panic")
		log.Error(err)
		http.Error(rw, err.Error(), http.StatusInternalServerError)
	})

	next(rw, r)
}
Beispiel #2
0
func api(at string, handler ApiHandlerFunc) http.HandlerFunc {
	return func(rw http.ResponseWriter, r *http.Request) {
		log := logger.New("ns=ccron-api").At(at).Start()

		err := handler(rw, r)

		if err != nil {
			log.Error(err)
			RenderError(rw, err)
			return
		}

		log.Log("state=success")
	}
}