summaryrefslogtreecommitdiff
path: root/system/addon/api.go
diff options
context:
space:
mode:
authorSteve <nilslice@gmail.com>2016-12-19 11:19:53 -0800
committerGitHub <noreply@github.com>2016-12-19 11:19:53 -0800
commit3791fadda7b761ffba38c567da29e2e71acd1dfb (patch)
tree79d810f9aafa1868ee0760983937470d0eea3db8 /system/addon/api.go
parentb20c5bdee38682edc851e646d815a34689c3c923 (diff)
[addons] Creating foundation for plugin-like system "Addons" (#24)
* adding addons dir and sample addon which enables the use of a new input element in forms for referencing other content. "addons" is a conceptual plugin-like feature, similar to wordpress "plugins" dir, but not as sophisticated
Diffstat (limited to 'system/addon/api.go')
-rw-r--r--system/addon/api.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/system/addon/api.go b/system/addon/api.go
new file mode 100644
index 0000000..4c3152b
--- /dev/null
+++ b/system/addon/api.go
@@ -0,0 +1,47 @@
+// Package addon provides an API for Ponzu addons to interface with the system
+package addon
+
+import (
+ "bytes"
+ "fmt"
+ "io/ioutil"
+ "log"
+ "net/http"
+ "time"
+
+ "github.com/bosssauce/ponzu/system/db"
+)
+
+// ContentAll retrives all items from the HTTP API within the provided namespace
+func ContentAll(namespace string) []byte {
+ host := db.ConfigCache("domain")
+ port := db.ConfigCache("http_port")
+ endpoint := "http://%s:%s/api/contents?type=%s"
+ buf := []byte{}
+ r := bytes.NewReader(buf)
+ url := fmt.Sprintf(endpoint, host, port, namespace)
+
+ req, err := http.NewRequest(http.MethodGet, url, r)
+ if err != nil {
+ log.Println("Error creating request for reference of:", namespace)
+ return nil
+ }
+
+ c := http.Client{
+ Timeout: time.Duration(time.Second * 5),
+ }
+ res, err := c.Do(req)
+ if err != nil {
+ log.Println("Error making HTTP request for reference of:", namespace)
+ return nil
+ }
+ defer res.Body.Close()
+
+ j, err := ioutil.ReadAll(res.Body)
+ if err != nil {
+ log.Println("Error reading request body for reference of:", namespace)
+ return nil
+ }
+
+ return j
+}