aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristine Dodrill <me@christine.website>2017-03-29 09:48:56 -0700
committerChristine Dodrill <me@christine.website>2017-03-29 09:48:56 -0700
commit60226001102de6ca0475cb9852a99f9e1b722937 (patch)
treef499f1d16b6d77fe8d7520a7e91a9ce5c8355f3a
parent19d1bc4a26285b7217a746df0981620416cca19b (diff)
downloadxesite-60226001102de6ca0475cb9852a99f9e1b722937.tar.xz
xesite-60226001102de6ca0475cb9852a99f9e1b722937.zip
rss feed generation in its own file
-rw-r--r--backend/christine.website/main.go60
-rw-r--r--backend/christine.website/rss.go67
2 files changed, 67 insertions, 60 deletions
diff --git a/backend/christine.website/main.go b/backend/christine.website/main.go
index d37d185..fa3e0ab 100644
--- a/backend/christine.website/main.go
+++ b/backend/christine.website/main.go
@@ -13,9 +13,7 @@ import (
"time"
"github.com/Xe/asarfs"
- "github.com/Xe/ln"
"github.com/gernest/front"
- "github.com/gorilla/feeds"
"github.com/urfave/negroni"
)
@@ -169,64 +167,6 @@ func main() {
log.Fatal(http.ListenAndServe(":"+port, n))
}
-var bootTime = time.Now()
-
-var feed = &feeds.Feed{
- Title: "Christine Dodrill's Blog",
- Link: &feeds.Link{Href: "https://christine.website/blog"},
- Description: "My blog posts and rants about various technology things.",
- Author: &feeds.Author{Name: "Christine Dodrill", Email: "me@christine.website"},
- Created: bootTime,
- Copyright: "This work is copyright Christine Dodrill. My viewpoints are my own and not the view of any employer past, current or future.",
-}
-
-func init() {
- for _, item := range posts {
- itime, _ := time.Parse("2006-01-02", item.Date)
- feed.Items = append(feed.Items, &feeds.Item{
- Title: item.Title,
- Link: &feeds.Link{Href: "https://christine.website/" + item.Link},
- Description: item.Summary,
- Created: itime,
- })
- }
-}
-
-// IncrediblySecureSalt *******
-const IncrediblySecureSalt = "hunter2"
-
-func createFeed(w http.ResponseWriter, r *http.Request) {
- w.Header().Set("Content-Type", "application/rss+xml")
- w.Header().Set("ETag", Hash(bootTime.String(), IncrediblySecureSalt))
-
- err := feed.WriteRss(w)
- if err != nil {
- http.Error(w, "Internal server error", http.StatusInternalServerError)
- ln.Error(err, ln.F{
- "remote_addr": r.RemoteAddr,
- "action": "generating_rss",
- "uri": r.RequestURI,
- "host": r.Host,
- })
- }
-}
-
-func createAtom(w http.ResponseWriter, r *http.Request) {
- w.Header().Set("Content-Type", "application/atom+xml")
- w.Header().Set("ETag", Hash(bootTime.String(), IncrediblySecureSalt))
-
- err := feed.WriteAtom(w)
- if err != nil {
- http.Error(w, "Internal server error", http.StatusInternalServerError)
- ln.Error(err, ln.F{
- "remote_addr": r.RemoteAddr,
- "action": "generating_rss",
- "uri": r.RequestURI,
- "host": r.Host,
- })
- }
-}
-
func writeBlogPosts(w http.ResponseWriter, r *http.Request) {
p := []interface{}{}
for _, post := range posts {
diff --git a/backend/christine.website/rss.go b/backend/christine.website/rss.go
new file mode 100644
index 0000000..b0cd445
--- /dev/null
+++ b/backend/christine.website/rss.go
@@ -0,0 +1,67 @@
+package main
+
+import (
+ "net/http"
+ "time"
+
+ "github.com/Xe/ln"
+ "github.com/gorilla/feeds"
+)
+
+var bootTime = time.Now()
+
+var feed = &feeds.Feed{
+ Title: "Christine Dodrill's Blog",
+ Link: &feeds.Link{Href: "https://christine.website/blog"},
+ Description: "My blog posts and rants about various technology things.",
+ Author: &feeds.Author{Name: "Christine Dodrill", Email: "me@christine.website"},
+ Created: bootTime,
+ Copyright: "This work is copyright Christine Dodrill. My viewpoints are my own and not the view of any employer past, current or future.",
+}
+
+func init() {
+ for _, item := range posts {
+ itime, _ := time.Parse("2006-01-02", item.Date)
+ feed.Items = append(feed.Items, &feeds.Item{
+ Title: item.Title,
+ Link: &feeds.Link{Href: "https://christine.website/" + item.Link},
+ Description: item.Summary,
+ Created: itime,
+ })
+ }
+}
+
+// IncrediblySecureSalt *******
+const IncrediblySecureSalt = "hunter2"
+
+func createFeed(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/rss+xml")
+ w.Header().Set("ETag", Hash(bootTime.String(), IncrediblySecureSalt))
+
+ err := feed.WriteRss(w)
+ if err != nil {
+ http.Error(w, "Internal server error", http.StatusInternalServerError)
+ ln.Error(err, ln.F{
+ "remote_addr": r.RemoteAddr,
+ "action": "generating_rss",
+ "uri": r.RequestURI,
+ "host": r.Host,
+ })
+ }
+}
+
+func createAtom(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/atom+xml")
+ w.Header().Set("ETag", Hash(bootTime.String(), IncrediblySecureSalt))
+
+ err := feed.WriteAtom(w)
+ if err != nil {
+ http.Error(w, "Internal server error", http.StatusInternalServerError)
+ ln.Error(err, ln.F{
+ "remote_addr": r.RemoteAddr,
+ "action": "generating_rss",
+ "uri": r.RequestURI,
+ "host": r.Host,
+ })
+ }
+}