diff options
author | Steve Manuel <nilslice@gmail.com> | 2016-10-28 13:05:23 -0700 |
---|---|---|
committer | Steve Manuel <nilslice@gmail.com> | 2016-10-28 13:05:23 -0700 |
commit | 8ff77bc0aa766dcd33fd4458557444defa76d87b (patch) | |
tree | d28b4790f7d45d96be15a98c2d4adc4caed0e50d /system/api/external.go | |
parent | c178f2e403b0b711d8aa3c0155d1368827f88afd (diff) |
adding initial components for anayltics tracking API requests
Diffstat (limited to 'system/api/external.go')
-rw-r--r-- | system/api/external.go | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/system/api/external.go b/system/api/external.go index e6e75f0..0da7eac 100644 --- a/system/api/external.go +++ b/system/api/external.go @@ -10,6 +10,7 @@ import ( // Externalable accepts or rejects external POST requests to /external/posts?type=Review type Externalable interface { + // Accepts determines whether a type will allow external submissions Accepts() bool } @@ -21,7 +22,7 @@ func externalPostsHandler(res http.ResponseWriter, req *http.Request) { err := req.ParseMultipartForm(1024 * 1024 * 4) // maxMemory 4MB if err != nil { - log.Println("[External]", err) + log.Println("[External] error:", err) res.WriteHeader(http.StatusInternalServerError) return } @@ -34,7 +35,7 @@ func externalPostsHandler(res http.ResponseWriter, req *http.Request) { p, found := content.Types[t] if !found { - log.Println("[External] Attempt to submit content", t, "by", req.RemoteAddr) + log.Println("[External] attempt to submit unknown type:", t, "from:", req.RemoteAddr) res.WriteHeader(http.StatusNotFound) return } @@ -43,15 +44,15 @@ func externalPostsHandler(res http.ResponseWriter, req *http.Request) { ext, ok := post.(Externalable) if !ok { - log.Println("[External]", err) - res.WriteHeader(http.StatusInternalServerError) + log.Println("[External] rejected non-externalable type:", t, "from:", req.RemoteAddr) + res.WriteHeader(http.StatusBadRequest) return } if ext.Accepts() { _, err := db.SetContent(t+"_external"+":-1", req.Form) if err != nil { - log.Println("[External]", err) + log.Println("[External] error:", err) res.WriteHeader(http.StatusInternalServerError) return } |