diff options
Diffstat (limited to 'service/transport.go')
-rw-r--r-- | service/transport.go | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/service/transport.go b/service/transport.go index 615fe2a..02e6106 100644 --- a/service/transport.go +++ b/service/transport.go @@ -54,6 +54,15 @@ func writeJson(c *client, data interface{}) error { }) } +func serveJsonError(w http.ResponseWriter, err error) { + var d = make(map[string]interface{}) + d["error"] = err.Error() + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusInternalServerError) + json.NewEncoder(w).Encode(d) + return +} + func redirect(c *client, url string) { c.w.Header().Add("Location", url) c.w.WriteHeader(http.StatusFound) @@ -640,6 +649,11 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { return writeJson(c, count) }, CSRF, JSON) + fStatus := handle(func(c *client) error { + id, _ := mux.Vars(c.r)["id"] + return s.StatusPopup(c, id) + }, SESSION, JSON) + r.HandleFunc("/", rootPage).Methods(http.MethodGet) r.HandleFunc("/nav", navPage).Methods(http.MethodGet) r.HandleFunc("/signin", signinPage).Methods(http.MethodGet) @@ -690,6 +704,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { r.HandleFunc("/fluoride/unlike/{id}", fUnlike).Methods(http.MethodPost) r.HandleFunc("/fluoride/retweet/{id}", fRetweet).Methods(http.MethodPost) r.HandleFunc("/fluoride/unretweet/{id}", fUnretweet).Methods(http.MethodPost) + r.HandleFunc("/fluoride/status/{id}", fStatus).Methods(http.MethodGet) r.PathPrefix("/static").Handler(http.StripPrefix("/static", http.FileServer(http.Dir(staticDir)))) |