diff options
author | Steve <nilslice@gmail.com> | 2017-02-13 11:06:14 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-13 11:06:14 -0800 |
commit | 4222b04d45b2932022c71eecf909e0e43f5f9d9d (patch) | |
tree | df0a0cc191834d9220fe5a9f952ad61c9527a43e /system/api/hide.go | |
parent | 7a85b284dec2bbb462969fb7e9e949b1a2ae720a (diff) | |
parent | 46d7c021d8de124be803b5c10f157c132343ab4e (diff) |
Merge pull request #73 from ponzu-cms/ponzu-dev
[core] Adding support to omit fields from json response, minor code reorganization
Diffstat (limited to 'system/api/hide.go')
-rw-r--r-- | system/api/hide.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/system/api/hide.go b/system/api/hide.go new file mode 100644 index 0000000..eed2c8b --- /dev/null +++ b/system/api/hide.go @@ -0,0 +1,27 @@ +package api + +import ( + "net/http" + + "github.com/ponzu-cms/ponzu/system/item" +) + +func hide(it interface{}, res http.ResponseWriter, req *http.Request) bool { + // check if should be hidden + if h, ok := it.(item.Hideable); ok { + err := h.Hide(res, req) + if err == item.ErrAllowHiddenItem { + return false + } + + if err != nil { + res.WriteHeader(http.StatusInternalServerError) + return true + } + + res.WriteHeader(http.StatusNotFound) + return true + } + + return false +} |