1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
package http
import (
"fmt"
"net/http"
"dev.mediocregopher.com/mediocre-blog.git/src/http/apiutil"
)
func (a *api) manageDraftPostsHandler() http.Handler {
tpl := a.mustParseBasedTpl("draft-posts-manage.html")
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
a.executeTemplate(rw, r, tpl, nil)
})
}
func (a *api) postDraftPostHandler() http.Handler {
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
p, err := postFromPostReq(r)
if err != nil {
apiutil.BadRequest(rw, r, err)
return
}
if err := a.params.PostDraftStore.Set(p); err != nil {
apiutil.InternalServerError(
rw, r, fmt.Errorf("storing post with id %q: %w", p.ID, err),
)
return
}
a.executeRedirectTpl(
rw, r, a.urlBuilder.Draft(p.ID).MethodEdit().String(),
)
})
}
|