summaryrefslogtreecommitdiff
path: root/system/api/handlers.go
diff options
context:
space:
mode:
authorSteve <nilslice@gmail.com>2016-10-31 00:59:57 -0700
committerGitHub <noreply@github.com>2016-10-31 00:59:57 -0700
commit645cfa39a92a9f732629f1e3206ca468ff329138 (patch)
tree89fc417b79394fb4fc58de997194b9730acfefc1 /system/api/handlers.go
parent96ebcb095797fe4947d647ad1aa7572d84609fc0 (diff)
parent682cc2b6d9e3524209fbe3d2773fa31e8de9b88d (diff)
Merge pull request #11 from bosssauce/ponzu-dev
[core] Enable content to be submitted from external clients
Diffstat (limited to 'system/api/handlers.go')
-rw-r--r--system/api/handlers.go17
1 files changed, 11 insertions, 6 deletions
diff --git a/system/api/handlers.go b/system/api/handlers.go
index 2ec82bb..8356683 100644
--- a/system/api/handlers.go
+++ b/system/api/handlers.go
@@ -3,13 +3,13 @@ package api
import (
"bytes"
"encoding/json"
- "fmt"
"log"
"net/http"
"strconv"
"strings"
"github.com/bosssauce/ponzu/content"
+ "github.com/bosssauce/ponzu/system/api/analytics"
"github.com/bosssauce/ponzu/system/db"
)
@@ -69,8 +69,6 @@ func postsHandler(res http.ResponseWriter, req *http.Request) {
all = append(all, post)
}
- fmt.Println(len(posts))
-
var start, end int
switch count {
case -1:
@@ -203,6 +201,7 @@ func SendJSON(res http.ResponseWriter, j map[string]interface{}) {
data, err = json.Marshal(j)
if err != nil {
+ log.Println(err)
data, _ = json.Marshal(map[string]interface{}{
"status": "fail",
"message": err.Error(),
@@ -212,9 +211,6 @@ func SendJSON(res http.ResponseWriter, j map[string]interface{}) {
sendData(res, data, 200)
}
-// ResponseFunc ...
-type ResponseFunc func(http.ResponseWriter, *http.Request)
-
// CORS wraps a HandleFunc to response to OPTIONS requests properly
func CORS(next http.HandlerFunc) http.HandlerFunc {
return http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
@@ -226,3 +222,12 @@ func CORS(next http.HandlerFunc) http.HandlerFunc {
next.ServeHTTP(res, req)
})
}
+
+// Record wraps a HandleFunc to record API requests for analytical purposes
+func Record(next http.HandlerFunc) http.HandlerFunc {
+ return http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
+ go analytics.Record(req)
+
+ next.ServeHTTP(res, req)
+ })
+}