示例#1
0
文件: main.go 项目: goodeggs/ccron
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)
}
示例#2
0
文件: api.go 项目: goodeggs/ccron
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")
	}
}