master
1package main
2
3import (
4 "log"
5 "net/http"
6 "io"
7)
8
9func rssProxy(feed string) http.Handler {
10 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
11 resp, err := http.Get(feed)
12 if err != nil{
13 log.Println(err)
14 }
15 _, err = io.Copy(w, resp.Body)
16 if err != nil{
17 log.Println(err)
18 }
19 return
20 })
21}
22
23func main() {
24 fs := http.FileServer(http.Dir("static"))
25 http.Handle("/", fs)
26 http.Handle("/rss1", rssProxy("http://rss.cnn.com/rss/cnn_topstories.rss"))
27 http.Handle("/rss2", rssProxy("http://www.aljazeera.com/xml/rss/all.xml"))
28 http.Handle("/rss3", rssProxy("http://espn.go.com/espn/rss/news"))
29
30 log.Println("Listening...")
31 http.ListenAndServe(":3000", nil)
32}