diff options
author | Steve Manuel <nilslice@gmail.com> | 2016-12-29 23:08:38 -0800 |
---|---|---|
committer | Steve Manuel <nilslice@gmail.com> | 2016-12-29 23:08:38 -0800 |
commit | e432bd36da61ac0a498f68fee8785c44ae800cc1 (patch) | |
tree | 5e08626cd7999cecdc5b171aa4e2e409355164b1 /system/api/push.go | |
parent | 7418572026f7ec9a35a85baf2cbf24c205740e4c (diff) |
move push func to separate file and adding tidwall/gjson to credits
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 + }) + } + } + } + +} |