summaryrefslogtreecommitdiff
path: root/system/api/external.go
diff options
context:
space:
mode:
authorSteve <nilslice@gmail.com>2017-01-26 10:48:40 -0800
committerGitHub <noreply@github.com>2017-01-26 10:48:40 -0800
commit16a159acec94fd391e840fab061ed08cf894369f (patch)
tree3418b9e58c9b967171bb5e5138a36cae3384f5c5 /system/api/external.go
parent3dea30f62a274db3e0cc95441338b2b71a751198 (diff)
[core] Embedded and implement http.Pusher into http.ResponseWriter+gzip Writer (#47)
* added http Pusher interface to gzip response writer * implement Pusher on gzipResponseWriter and pass encoding header to pusher options * providing a generic error view fuction for code that calls a interface method which will have access to the response * fix []byte -> string type for fmt string * adding the res, req pattern for method arguments in interfaces and their method calls * fix for spacing in generic error message * remove default error views displayed in lifecycle hooks - will rely on custom views or redirects inside hook now that user has ResponseWriter. Otherwise, multiple WriteHeader calls would be warned * removing WriteHeader calls before return in external handlers * bump version 0.8.1
Diffstat (limited to 'system/api/external.go')
-rw-r--r--system/api/external.go27
1 files changed, 11 insertions, 16 deletions
diff --git a/system/api/external.go b/system/api/external.go
index 5a74107..168575a 100644
--- a/system/api/external.go
+++ b/system/api/external.go
@@ -17,13 +17,13 @@ import (
// /external/content?type=Review
type Externalable interface {
// Accept allows external content submissions of a specific type
- Accept(req *http.Request) error
+ Accept(http.ResponseWriter, *http.Request) error
}
// Trustable allows external content to be auto-approved, meaning content sent
// as an Externalable will be stored in the public content bucket
type Trustable interface {
- AutoApprove(req *http.Request) error
+ AutoApprove(http.ResponseWriter, *http.Request) error
}
func externalContentHandler(res http.ResponseWriter, req *http.Request) {
@@ -125,10 +125,9 @@ func externalContentHandler(res http.ResponseWriter, req *http.Request) {
// call Accept with the request, enabling developer to add or chack data
// before saving to DB
- err = ext.Accept(req)
+ err = ext.Accept(res, req)
if err != nil {
- log.Println(err)
- res.WriteHeader(http.StatusInternalServerError)
+ log.Println("[External} error calling Accept:", err)
return
}
@@ -139,10 +138,9 @@ func externalContentHandler(res http.ResponseWriter, req *http.Request) {
return
}
- err = hook.BeforeSave(req)
+ err = hook.BeforeSave(res, req)
if err != nil {
- log.Println("[External] error:", err)
- res.WriteHeader(http.StatusInternalServerError)
+ log.Println("[External] error calling BeforeSave:", err)
return
}
@@ -152,10 +150,9 @@ func externalContentHandler(res http.ResponseWriter, req *http.Request) {
// check if the content is Trustable should be auto-approved
trusted, ok := post.(Trustable)
if ok {
- err := trusted.AutoApprove(req)
+ err := trusted.AutoApprove(res, req)
if err != nil {
- log.Println("[External] error:", err)
- res.WriteHeader(http.StatusInternalServerError)
+ log.Println("[External] error calling AutoApprove:", err)
return
}
} else {
@@ -164,8 +161,7 @@ func externalContentHandler(res http.ResponseWriter, req *http.Request) {
id, err := db.SetContent(t+spec+":-1", req.PostForm)
if err != nil {
- log.Println("[External] error:", err)
- res.WriteHeader(http.StatusInternalServerError)
+ log.Println("[External] error calling SetContent:", err)
return
}
@@ -173,10 +169,9 @@ func externalContentHandler(res http.ResponseWriter, req *http.Request) {
ctx := context.WithValue(req.Context(), "target", fmt.Sprintf("%s:%d", t, id))
req = req.WithContext(ctx)
- err = hook.AfterSave(req)
+ err = hook.AfterSave(res, req)
if err != nil {
- log.Println("[External] error:", err)
- res.WriteHeader(http.StatusInternalServerError)
+ log.Println("[External] error calling AfterSave:", err)
return
}