2017-05-20 22:06:30 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-05-20 22:40:12 +00:00
|
|
|
"encoding/json"
|
2017-05-20 22:06:30 +00:00
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
|
2019-01-12 17:05:00 +00:00
|
|
|
"within.website/ln"
|
2017-05-20 22:06:30 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var bootTime = time.Now()
|
2019-01-26 14:38:22 +00:00
|
|
|
var etag = Hash(bootTime.String(), IncrediblySecureSalt)
|
2017-05-20 22:06:30 +00:00
|
|
|
|
|
|
|
// IncrediblySecureSalt *******
|
|
|
|
const IncrediblySecureSalt = "hunter2"
|
|
|
|
|
|
|
|
func (s *Site) createFeed(w http.ResponseWriter, r *http.Request) {
|
|
|
|
w.Header().Set("Content-Type", "application/rss+xml")
|
|
|
|
w.Header().Set("ETag", Hash(bootTime.String(), IncrediblySecureSalt))
|
|
|
|
|
|
|
|
err := s.rssFeed.WriteRss(w)
|
|
|
|
if err != nil {
|
|
|
|
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
2017-12-13 18:49:13 +00:00
|
|
|
ln.Error(r.Context(), err, ln.F{
|
2017-05-20 22:06:30 +00:00
|
|
|
"remote_addr": r.RemoteAddr,
|
|
|
|
"action": "generating_rss",
|
|
|
|
"uri": r.RequestURI,
|
|
|
|
"host": r.Host,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Site) createAtom(w http.ResponseWriter, r *http.Request) {
|
|
|
|
w.Header().Set("Content-Type", "application/atom+xml")
|
|
|
|
w.Header().Set("ETag", Hash(bootTime.String(), IncrediblySecureSalt))
|
|
|
|
|
|
|
|
err := s.rssFeed.WriteAtom(w)
|
|
|
|
if err != nil {
|
|
|
|
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
2017-12-13 18:49:13 +00:00
|
|
|
ln.Error(r.Context(), err, ln.F{
|
2017-05-20 22:06:30 +00:00
|
|
|
"remote_addr": r.RemoteAddr,
|
2017-05-20 22:40:12 +00:00
|
|
|
"action": "generating_atom",
|
|
|
|
"uri": r.RequestURI,
|
|
|
|
"host": r.Host,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Site) createJsonFeed(w http.ResponseWriter, r *http.Request) {
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
w.Header().Set("ETag", Hash(bootTime.String(), IncrediblySecureSalt))
|
|
|
|
|
|
|
|
e := json.NewEncoder(w)
|
|
|
|
e.SetIndent("", "\t")
|
|
|
|
err := e.Encode(s.jsonFeed)
|
|
|
|
if err != nil {
|
|
|
|
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
2017-12-13 18:49:13 +00:00
|
|
|
ln.Error(r.Context(), err, ln.F{
|
2017-05-20 22:40:12 +00:00
|
|
|
"remote_addr": r.RemoteAddr,
|
|
|
|
"action": "generating_jsonfeed",
|
2017-05-20 22:06:30 +00:00
|
|
|
"uri": r.RequestURI,
|
|
|
|
"host": r.Host,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|