Move RecoverPanics to be the top level wrapped handler. Add new method to be sure a logger has been generated instead of assuming one has. Move regexp list compilation into a utility and pass regexp list into CORS.

This commit is contained in:
Jessica Forrester
2014-09-04 13:55:30 -04:00
parent 8b4ca9c2a7
commit becf6ca4e7
8 changed files with 38 additions and 21 deletions

View File

@@ -95,6 +95,15 @@ func LogOf(w http.ResponseWriter) *respLogger {
panic("Logger not installed yet!")
}
// Returns the existing logger hiding in w. If there is not an existing logger
// then one will be created.
func FindOrCreateLogOf(req *http.Request, w *http.ResponseWriter) *respLogger {
if _, exists := (*w).(*respLogger); !exists {
NewLogged(req, w)
}
return LogOf(*w)
}
// Unlogged returns the original ResponseWriter, or w if it is not our inserted logger.
func Unlogged(w http.ResponseWriter) http.ResponseWriter {
if rl, ok := w.(*respLogger); ok {