diff --git a/assets/index.html b/assets/index.html new file mode 100644 index 0000000..94676f4 --- /dev/null +++ b/assets/index.html @@ -0,0 +1,12 @@ + + + + + White Rabbit Podcasting CMS + + + +

White Rabbit Podcasting CMS

+

Git Galaxy Podcast

+ + \ No newline at end of file diff --git a/assets/static/styles.css b/assets/static/styles.css new file mode 100644 index 0000000..d60afbd --- /dev/null +++ b/assets/static/styles.css @@ -0,0 +1,3 @@ +body { + background-color: blue; +} \ No newline at end of file diff --git a/webserver.go b/webserver.go index e319731..2b394dc 100644 --- a/webserver.go +++ b/webserver.go @@ -5,8 +5,10 @@ import ( "log" "io/ioutil" "net/http" + + "github.com/gorilla/mux" ) -func rootHandler(w http.ResponseWriter, r *http.Request) { +func RssHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/rss+xml") w.WriteHeader(http.StatusOK) data, err := ioutil.ReadFile("feed.rss") @@ -17,9 +19,28 @@ func rootHandler(w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, string(data)) } +func HomeHandler(w http.ResponseWriter, r *http.Request) { + data, err := ioutil.ReadFile("assets/index.html") + + if err == nil { + w.Write(data) + } else { + w.WriteHeader(404) + w.Write([]byte("404 Something went wrong - " + http.StatusText(404))) + } +} + +func DownloadHandler(w http.ResponseWriter, r *http.Request) { + w.Write([]byte("Gorilla!\n")) +} + func main() { go watch() - http.HandleFunc("/", rootHandler) - log.Fatal(http.ListenAndServe(":8080", nil)) - fmt.Println("watching folder") + r := mux.NewRouter() + r.PathPrefix("/assets/").Handler(http.StripPrefix("/assets/", http.FileServer(http.Dir("assets/static")))) + r.HandleFunc("/", HomeHandler) + r.HandleFunc("/download/{episode}", DownloadHandler) + r.HandleFunc("/rss", RssHandler) + http.Handle("/", r) + log.Fatal(http.ListenAndServe(":8000", r)) } \ No newline at end of file