diff options
author | Steve Manuel <nilslice@gmail.com> | 2017-08-15 15:43:49 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-15 15:43:49 -0600 |
commit | c9a6c2ef34d4c290223963d6e836926c6b58eb1b (patch) | |
tree | 5344df00833337f3b16e59ef80ffdf2efa5b0a5e /system/api/omit.go | |
parent | 4818fd1fd68f6c8f1afe0c730cf4bca1861e6589 (diff) | |
parent | 9a14fd72fe0c771d45c79069c65ac9a7170dcaf2 (diff) |
Merge pull request #184 from ponzu-cms/ponzu-dev
[core] update Omittable, Pushable interfaces and implementations to take res/req pair and hydrate item for caller
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()) |