diff options
Diffstat (limited to 'system/api/push.go')
-rw-r--r-- | system/api/push.go | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/system/api/push.go b/system/api/push.go new file mode 100644 index 0000000..64eb5b0 --- /dev/null +++ b/system/api/push.go @@ -0,0 +1,36 @@ +package api + +import ( + "log" + + "github.com/ponzu-cms/ponzu/system/item" + + "github.com/tidwall/gjson" +) + +func push(res http.ResponseWriter, pt func() interface{}, data []byte) { + // Push(target string, opts *PushOptions) error + if pusher, ok := res.(http.Pusher); ok { + if p, ok := pt().(item.Pushable); ok { + // get fields to pull values from data + fields := p.Push() + + // parse values from data to push + values := gjson.GetManyBytes(data, fields...) + + // push all values from Pushable items' fields + for i := range values { + val := values[i] + val.ForEach(func(k, v gjson.Result) bool { + err := pusher.Push(v.String(), nil) + if err != nil { + log.Println("Error during Push of value:", v.String()) + } + + return true + }) + } + } + } + +} |