diff options
author | Alex Scerba <alex@scerba.org> | 2025-02-11 13:57:20 -0500 |
---|---|---|
committer | Alex Scerba <alex@scerba.org> | 2025-02-11 13:57:20 -0500 |
commit | c452c2c5784659436e0ab8775ecb69fe4d5ebe6a (patch) | |
tree | f36d3d4f3fd0787e5f0a2a055edd66e7f517acaa /cmd | |
parent | 7cef22cd87d160c2484c572c8a4248d4b64c076f (diff) |
Implement feed handling
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/http/handle.go | 12 | ||||
-rw-r--r-- | cmd/http/main.go | 1 |
2 files changed, 13 insertions, 0 deletions
diff --git a/cmd/http/handle.go b/cmd/http/handle.go index f5ee67a..3d49a59 100644 --- a/cmd/http/handle.go +++ b/cmd/http/handle.go @@ -1,8 +1,10 @@ package main import ( + "bytes" "net/http" "strings" + "time" ) func (app *application) home(w http.ResponseWriter, r *http.Request) { @@ -108,3 +110,13 @@ func (app *application) archive(w http.ResponseWriter, r *http.Request) { } } } + +func (app application) feed(w http.ResponseWriter, r *http.Request) { + p, err := app.aggregate("html/blog") + if err != nil { + app.serverError(w, err) + } + w.Header().Set("Content-Type", "application/atom+xml") + feed := bytes.NewReader(generateFeed(r.Host, p)) + http.ServeContent(w, r, "atom.xml", time.Now(), feed) +} diff --git a/cmd/http/main.go b/cmd/http/main.go index 951c02f..8f293d4 100644 --- a/cmd/http/main.go +++ b/cmd/http/main.go @@ -70,6 +70,7 @@ func main() { mux.HandleFunc("/blog/", app.blog) mux.HandleFunc("/archive", app.archive) mux.HandleFunc("/archive/", app.archive) + mux.HandleFunc("/atom.xml", app.feed) mux.HandleFunc("/", app.home) if *addr == ":443" { |