backend: don't send post bodies to post listing clients

This commit is contained in:
Cadey Ratio 2016-12-18 08:56:35 -08:00
parent dba3ae46f8
commit 5ec7046253
1 changed files with 15 additions and 1 deletions

View File

@ -134,7 +134,21 @@ func main() {
} }
func writeBlogPosts(w http.ResponseWriter, r *http.Request) { func writeBlogPosts(w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode(posts) p := []interface{}{}
for _, post := range posts {
p = append(p, struct {
Title string `json:"title"`
Link string `json:"link"`
Summary string `json:"summary,omitifempty"`
Date string `json:"date"`
}{
Title: post.Title,
Link: post.Link,
Summary: post.Summary,
Date: post.Date,
})
}
json.NewEncoder(w).Encode(p)
} }
func writeIndexHTML(w http.ResponseWriter, r *http.Request) { func writeIndexHTML(w http.ResponseWriter, r *http.Request) {