func ctx(conf *Conf, db database.Db, r *http.Request, loggedIn bool) Context { return Context{ Entries: db.Get(), LoggedIn: loggedIn, Title: conf.Title, Description: markdown.Render(conf.Description), SafeDesc: conf.Description, Url: conf.URL, } }
func Add(conf *Conf, db database.Db, es eventsource.EventSource) http.Handler { return mux.Method{ "GET": http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { body := views.Add.RenderInLayout(views.Layout, ctx(conf, db, r, true)) w.Header().Add("Content-Type", "text/html") fmt.Fprintf(w, body) }), "POST": http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { db.Save(time.Now(), r.PostFormValue("body")) es.SendEventMessage(r.PostFormValue("body"), "add-post", "") http.Redirect(w, r, "/", 301) }), } }