summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md1
-rw-r--r--system/api/handlers.go31
-rw-r--r--system/api/push.go36
3 files changed, 39 insertions, 29 deletions
diff --git a/README.md b/README.md
index 9467fff..2c08a89 100644
--- a/README.md
+++ b/README.md
@@ -183,6 +183,7 @@ $ ponzu --dev --fork=github.com/nilslice/ponzu new /path/to/new/project
- [github.com/nilslice/email](https://github.com/nilslice/email)
- [github.com/gorilla/schema](https://github.com/gorilla/schema)
- [github.com/satori/go.uuid](https://github.com/satori/go.uuid)
+- [github.com/tidwall/gjson](https://github.com/tidwall/gjson)
- [github.com/boltdb/bolt](https://github.com/boltdb/bolt)
- [github.com/sluu99/um](https://github.com/sluu99/um)
- [Materialnote Editor](http://www.web-forge.info/projects/materialNote)
diff --git a/system/api/handlers.go b/system/api/handlers.go
index a152301..a01f3dc 100644
--- a/system/api/handlers.go
+++ b/system/api/handlers.go
@@ -11,7 +11,6 @@ import (
"github.com/ponzu-cms/ponzu/system/api/analytics"
"github.com/ponzu-cms/ponzu/system/db"
"github.com/ponzu-cms/ponzu/system/item"
- "github.com/tidwall/gjson"
)
func typesHandler(res http.ResponseWriter, req *http.Request) {
@@ -99,7 +98,8 @@ func contentHandler(res http.ResponseWriter, req *http.Request) {
return
}
- if pt, ok := item.Types[t]; !ok {
+ pt, ok := item.Types[t]
+ if !ok {
res.WriteHeader(http.StatusNotFound)
return
}
@@ -183,33 +183,6 @@ func toJSON(data []string) ([]byte, error) {
return buf.Bytes(), nil
}
-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
- })
- }
- }
- }
-
-}
-
// sendData() should be used any time you want to communicate
// data back to a foreign client
func sendData(res http.ResponseWriter, data []byte, code int) {
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
+ })
+ }
+ }
+ }
+
+}