diff options
author | Steve Manuel <nilslice@gmail.com> | 2017-08-15 13:39:00 -0600 |
---|---|---|
committer | Steve Manuel <nilslice@gmail.com> | 2017-08-15 15:14:52 -0600 |
commit | 075aba63ff98f6f16383f27895856da1569761c4 (patch) | |
tree | db6ae78b4770ae728d7c5623cb1214d4ef006910 /system/api/omit.go | |
parent | 4818fd1fd68f6c8f1afe0c730cf4bca1861e6589 (diff) |
update Omittable, Pushable, interface to take res, req pair like Hooks, update implementations & hydrate items
Diffstat (limited to 'system/api/omit.go')
-rw-r--r-- | system/api/omit.go | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/system/api/omit.go b/system/api/omit.go index 909e3ad..e8960bb 100644 --- a/system/api/omit.go +++ b/system/api/omit.go @@ -3,6 +3,7 @@ package api import ( "fmt" "log" + "net/http" "github.com/ponzu-cms/ponzu/system/item" @@ -10,19 +11,22 @@ import ( "github.com/tidwall/sjson" ) -func omit(it interface{}, data []byte) ([]byte, error) { +func omit(res http.ResponseWriter, req *http.Request, it interface{}, data []byte) ([]byte, error) { // is it Omittable om, ok := it.(item.Omittable) if !ok { return data, nil } - return omitFields(om, data, "data") + return omitFields(res, req, om, data, "data") } -func omitFields(om item.Omittable, data []byte, pathPrefix string) ([]byte, error) { +func omitFields(res http.ResponseWriter, req *http.Request, om item.Omittable, data []byte, pathPrefix string) ([]byte, error) { // get fields to omit from json data - fields := om.Omit() + fields, err := om.Omit(res, req) + if err != nil { + return nil, err + } // remove each field from json, all responses contain json object(s) in top-level "data" array n := int(gjson.GetBytes(data, pathPrefix+".#").Int()) |