diff options
author | Ollie Phillips <oliver@eantics.co.uk> | 2019-05-09 16:14:15 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-09 16:14:15 +0100 |
commit | 75d316ccfb4500d618b8745a8c97ee9eac16c05b (patch) | |
tree | c322e6873e1f7a5c5bc4349fb5db5ebed8ab4e33 /system/item | |
parent | 8882d90229ec0fd8db592e15585e0627dca379d4 (diff) | |
parent | d337a2251d087e2d9bfc96ae130688a4dab6348f (diff) |
Merge pull request #305 from olliephillips/ponzu-dev
Tentatively merging this @nilslice. The code and markdown docs are complete I think. As I understand it, you'll need to merge it to master. I can't do that - and a good thing too ;) I'll do the same on the main docs repo also
Diffstat (limited to 'system/item')
-rw-r--r-- | system/item/item.go | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/system/item/item.go b/system/item/item.go index 1108ae0..34ced58 100644 --- a/system/item/item.go +++ b/system/item/item.go @@ -24,13 +24,13 @@ func init() { // We store the compiled regex as the key // and assign the replacement as the map's value. rxList = map[*regexp.Regexp][]byte{ - regexp.MustCompile("`[-]+`"): []byte("-"), - regexp.MustCompile("[[:space:]]"): []byte("-"), - regexp.MustCompile("[[:blank:]]"): []byte(""), - regexp.MustCompile("`[^a-z0-9]`i"): []byte("-"), - regexp.MustCompile("[!/:-@[-`{-~]"): []byte(""), - regexp.MustCompile("/[^\x20-\x7F]/"): []byte(""), - regexp.MustCompile("`&(amp;)?#?[a-z0-9]+;`i"): []byte("-"), + regexp.MustCompile("`[-]+`"): []byte("-"), + regexp.MustCompile("[[:space:]]"): []byte("-"), + regexp.MustCompile("[[:blank:]]"): []byte(""), + regexp.MustCompile("`[^a-z0-9]`i"): []byte("-"), + regexp.MustCompile("[!/:-@[-`{-~]"): []byte(""), + regexp.MustCompile("/[^\x20-\x7F]/"): []byte(""), + regexp.MustCompile("`&(amp;)?#?[a-z0-9]+;`i"): []byte("-"), regexp.MustCompile("`&([a-z])(acute|uml|circ|grave|ring|cedil|slash|tilde|caron|lig|quot|rsquo);`i"): []byte("\\1"), } } @@ -65,6 +65,9 @@ type Sortable interface { // to the different lifecycles/events a struct may encounter. Item implements // Hookable with no-ops so our user can override only whichever ones necessary. type Hookable interface { + BeforeAPIResponse(http.ResponseWriter, *http.Request, []byte) ([]byte, error) + AfterAPIResponse(http.ResponseWriter, *http.Request, []byte) error + BeforeAPICreate(http.ResponseWriter, *http.Request) error AfterAPICreate(http.ResponseWriter, *http.Request) error @@ -177,6 +180,16 @@ func (i Item) String() string { return fmt.Sprintf("Item ID: %s", i.UniqueID()) } +// BeforeAPIResponse is a no-op to ensure structs which embed Item implement Hookable +func (i Item) BeforeAPIResponse(res http.ResponseWriter, req *http.Request, data []byte) ([]byte, error) { + return data, nil +} + +// AfterAPIResponse is a no-op to ensure structs which embed Item implement Hookable +func (i Item) AfterAPIResponse(res http.ResponseWriter, req *http.Request, data []byte) error { + return nil +} + // BeforeAPICreate is a no-op to ensure structs which embed Item implement Hookable func (i Item) BeforeAPICreate(res http.ResponseWriter, req *http.Request) error { return nil |