mirror of
https://github.com/gmemstr/pogo.git
synced 2024-09-20 01:31:09 +01:00
Implemented Gorilla mux router & index page
Working on a simple frontend for displaying various things e.g latest episode etc.
This commit is contained in:
parent
78d955b116
commit
581f7671f7
12
assets/index.html
Normal file
12
assets/index.html
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>White Rabbit Podcasting CMS</title>
|
||||||
|
<link rel="stylesheet" href="/assets/styles.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>White Rabbit Podcasting CMS</h1>
|
||||||
|
<p>Git Galaxy Podcast</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
3
assets/static/styles.css
Normal file
3
assets/static/styles.css
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
body {
|
||||||
|
background-color: blue;
|
||||||
|
}
|
29
webserver.go
29
webserver.go
|
@ -5,8 +5,10 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"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.Header().Set("Content-Type", "application/rss+xml")
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
data, err := ioutil.ReadFile("feed.rss")
|
data, err := ioutil.ReadFile("feed.rss")
|
||||||
|
@ -17,9 +19,28 @@ func rootHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
fmt.Fprint(w, string(data))
|
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() {
|
func main() {
|
||||||
go watch()
|
go watch()
|
||||||
http.HandleFunc("/", rootHandler)
|
r := mux.NewRouter()
|
||||||
log.Fatal(http.ListenAndServe(":8080", nil))
|
r.PathPrefix("/assets/").Handler(http.StripPrefix("/assets/", http.FileServer(http.Dir("assets/static"))))
|
||||||
fmt.Println("watching folder")
|
r.HandleFunc("/", HomeHandler)
|
||||||
|
r.HandleFunc("/download/{episode}", DownloadHandler)
|
||||||
|
r.HandleFunc("/rss", RssHandler)
|
||||||
|
http.Handle("/", r)
|
||||||
|
log.Fatal(http.ListenAndServe(":8000", r))
|
||||||
}
|
}
|
Loading…
Reference in a new issue