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

@@ -19,6 +19,7 @@ package util
import (
"encoding/json"
"fmt"
"regexp"
"runtime"
"time"
@@ -162,3 +163,16 @@ func StringDiff(a, b string) string {
out = append(out, []byte("\n\n")...)
return string(out)
}
// Takes a list of strings and compiles them into a list of regular expressions
func CompileRegexps(regexpStrings StringList) ([]*regexp.Regexp, error) {
regexps := []*regexp.Regexp{}
for _, regexpStr := range regexpStrings {
r, err := regexp.Compile(regexpStr)
if err != nil {
return []*regexp.Regexp{}, err
}
regexps = append(regexps, r)
}
return regexps, nil
}