mirror of
https://github.com/gmemstr/pogo.git
synced 2024-09-20 01:31:09 +01:00
Run gofmt tool on source files
This commit is contained in:
parent
4727da5c8a
commit
18267d0362
64
src/admin.go
64
src/admin.go
|
@ -1,5 +1,5 @@
|
||||||
/* admin.go
|
/* admin.go
|
||||||
*
|
*
|
||||||
* Here is where all the neccesary functions for managing episodes
|
* Here is where all the neccesary functions for managing episodes
|
||||||
* live, e.g adding removing etc.
|
* live, e.g adding removing etc.
|
||||||
*/
|
*/
|
||||||
|
@ -7,12 +7,12 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
"io/ioutil"
|
|
||||||
"io"
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
"os" // ioOS?
|
"os" // ioOS?
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Write custom CSS to disk or send it back to the client if GET
|
// Write custom CSS to disk or send it back to the client if GET
|
||||||
|
@ -23,18 +23,18 @@ func CustomCss(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
filename := "custom.css"
|
filename := "custom.css"
|
||||||
|
|
||||||
err := ioutil.WriteFile("./assets/static/" + filename, []byte(css), 0644)
|
err := ioutil.WriteFile("./assets/static/"+filename, []byte(css), 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.Write([]byte("<script>window.location = '/admin#failed';</script>"))
|
w.Write([]byte("<script>window.location = '/admin#failed';</script>"))
|
||||||
|
|
||||||
panic(err)
|
panic(err)
|
||||||
} else {
|
} else {
|
||||||
w.Write([]byte("<script>window.location = '/admin#cssupdated';</script>"))
|
w.Write([]byte("<script>window.location = '/admin#cssupdated';</script>"))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
css,err := ioutil.ReadFile("./assets/static/custom.css")
|
css, err := ioutil.ReadFile("./assets/static/custom.css")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic (err)
|
panic(err)
|
||||||
} else {
|
} else {
|
||||||
w.Write(css)
|
w.Write(css)
|
||||||
}
|
}
|
||||||
|
@ -49,39 +49,39 @@ func CreateEpisode(w http.ResponseWriter, r *http.Request) {
|
||||||
date := strings.Join(r.Form["date"], "")
|
date := strings.Join(r.Form["date"], "")
|
||||||
title := strings.Join(r.Form["title"], "")
|
title := strings.Join(r.Form["title"], "")
|
||||||
|
|
||||||
name := fmt.Sprintf("%v_%v", date, title)
|
name := fmt.Sprintf("%v_%v", date, title)
|
||||||
filename := name + ".mp3"
|
filename := name + ".mp3"
|
||||||
shownotes := name + "_SHOWNOTES.md"
|
shownotes := name + "_SHOWNOTES.md"
|
||||||
fmt.Println(name)
|
fmt.Println(name)
|
||||||
description := strings.Join(r.Form["description"], "")
|
description := strings.Join(r.Form["description"], "")
|
||||||
fmt.Println(description)
|
fmt.Println(description)
|
||||||
// Finish building filenames
|
// Finish building filenames
|
||||||
|
|
||||||
err := ioutil.WriteFile("./podcasts/" + shownotes, []byte(description), 0644)
|
err := ioutil.WriteFile("./podcasts/"+shownotes, []byte(description), 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.Write([]byte("<script>window.location = '/admin#failed';</script>"))
|
w.Write([]byte("<script>window.location = '/admin#failed';</script>"))
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
file, handler, err := r.FormFile("file")
|
file, handler, err := r.FormFile("file")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.Write([]byte("<script>window.location = '/admin#failed';</script>"))
|
w.Write([]byte("<script>window.location = '/admin#failed';</script>"))
|
||||||
|
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
fmt.Println(handler.Header)
|
fmt.Println(handler.Header)
|
||||||
f, err := os.OpenFile("./podcasts/"+filename, os.O_WRONLY|os.O_CREATE, 0666)
|
f, err := os.OpenFile("./podcasts/"+filename, os.O_WRONLY|os.O_CREATE, 0666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.Write([]byte("<script>window.location = '/admin#failed';</script>"))
|
w.Write([]byte("<script>window.location = '/admin#failed';</script>"))
|
||||||
|
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
io.Copy(f, file)
|
io.Copy(f, file)
|
||||||
w.Write([]byte("<script>window.location = '/admin#published';</script>"))
|
w.Write([]byte("<script>window.location = '/admin#published';</script>"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ func RemoveEpisode(w http.ResponseWriter, r *http.Request) {
|
||||||
// Remove MP3 first
|
// Remove MP3 first
|
||||||
r.ParseMultipartForm(32 << 20)
|
r.ParseMultipartForm(32 << 20)
|
||||||
|
|
||||||
episode := strings.Join(r.Form["episode"],"")
|
episode := strings.Join(r.Form["episode"], "")
|
||||||
os.Remove(episode)
|
os.Remove(episode)
|
||||||
sn := strings.Replace(episode, ".mp3", "_SHOWNOTES.md", 2)
|
sn := strings.Replace(episode, ".mp3", "_SHOWNOTES.md", 2)
|
||||||
os.Remove(sn)
|
os.Remove(sn)
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
/* generate_rss.go
|
/* generate_rss.go
|
||||||
*
|
*
|
||||||
* This file contains functions for monitoring for file changes and
|
* This file contains functions for monitoring for file changes and
|
||||||
* regenerating the RSS feed accordingly, pulling in shownote files
|
* regenerating the RSS feed accordingly, pulling in shownote files
|
||||||
* and configuration parameters
|
* and configuration parameters
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ func watch() {
|
||||||
viper.SetConfigName("config")
|
viper.SetConfigName("config")
|
||||||
viper.AddConfigPath(".")
|
viper.AddConfigPath(".")
|
||||||
err := viper.ReadInConfig() // Find and read the config file
|
err := viper.ReadInConfig() // Find and read the config file
|
||||||
if err != nil { // Handle errors reading the config file
|
if err != nil { // Handle errors reading the config file
|
||||||
panic(fmt.Errorf("Fatal error config file: %s \n", err))
|
panic(fmt.Errorf("Fatal error config file: %s \n", err))
|
||||||
}
|
}
|
||||||
watcher, err := fsnotify.NewWatcher()
|
watcher, err := fsnotify.NewWatcher()
|
||||||
|
@ -63,14 +63,13 @@ func watch() {
|
||||||
<-done
|
<-done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Called when a file has been created / changed, uses gorilla feeds
|
// Called when a file has been created / changed, uses gorilla feeds
|
||||||
// fork to add items to feed object
|
// fork to add items to feed object
|
||||||
func generate_rss() {
|
func generate_rss() {
|
||||||
viper.SetConfigName("config")
|
viper.SetConfigName("config")
|
||||||
viper.AddConfigPath(".")
|
viper.AddConfigPath(".")
|
||||||
err := viper.ReadInConfig() // Find and read the config file
|
err := viper.ReadInConfig() // Find and read the config file
|
||||||
if err != nil { // Handle errors reading the config file
|
if err != nil { // Handle errors reading the config file
|
||||||
panic(fmt.Errorf("Fatal error config file: %s \n", err))
|
panic(fmt.Errorf("Fatal error config file: %s \n", err))
|
||||||
}
|
}
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
@ -84,7 +83,7 @@ func generate_rss() {
|
||||||
Title: viper.GetString("Name"),
|
Title: viper.GetString("Name"),
|
||||||
Link: &feeds.Link{Href: podcasturl},
|
Link: &feeds.Link{Href: podcasturl},
|
||||||
Description: viper.GetString("Description"),
|
Description: viper.GetString("Description"),
|
||||||
Author: &feeds.Author{Name: viper.GetString("Host"), Email:viper.GetString("Email")},
|
Author: &feeds.Author{Name: viper.GetString("Host"), Email: viper.GetString("Email")},
|
||||||
Created: now,
|
Created: now,
|
||||||
Image: &feeds.Image{Url: viper.GetString("Image")},
|
Image: &feeds.Image{Url: viper.GetString("Image")},
|
||||||
}
|
}
|
||||||
|
@ -94,17 +93,17 @@ func generate_rss() {
|
||||||
s := strings.Split(file.Name(), "_")
|
s := strings.Split(file.Name(), "_")
|
||||||
t := strings.Split(s[1], ".")
|
t := strings.Split(s[1], ".")
|
||||||
title := t[0]
|
title := t[0]
|
||||||
description,err := ioutil.ReadFile("podcasts/" + strings.Replace(file.Name(), ".mp3", "_SHOWNOTES.md", 2))
|
description, err := ioutil.ReadFile("podcasts/" + strings.Replace(file.Name(), ".mp3", "_SHOWNOTES.md", 2))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
date, err := time.Parse("2006-01-02", s[0])
|
date, err := time.Parse("2006-01-02", s[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
size := fmt.Sprintf("%d", file.Size())
|
size := fmt.Sprintf("%d", file.Size())
|
||||||
link := podcasturl + "/download/" + file.Name()
|
link := podcasturl + "/download/" + file.Name()
|
||||||
feed.Add (
|
feed.Add(
|
||||||
&feeds.Item{
|
&feeds.Item{
|
||||||
Title: title,
|
Title: title,
|
||||||
Link: &feeds.Link{Href: link, Length: size, Type: "audio/mpeg"},
|
Link: &feeds.Link{Href: link, Length: size, Type: "audio/mpeg"},
|
||||||
|
@ -129,10 +128,10 @@ func generate_rss() {
|
||||||
}
|
}
|
||||||
// fmt.Println(rss)
|
// fmt.Println(rss)
|
||||||
|
|
||||||
// Write to files as neccesary
|
// Write to files as neccesary
|
||||||
rss_byte := []byte(rss)
|
rss_byte := []byte(rss)
|
||||||
ioutil.WriteFile("feed.rss", rss_byte, 0644)
|
ioutil.WriteFile("feed.rss", rss_byte, 0644)
|
||||||
|
|
||||||
json_byte := []byte(json)
|
json_byte := []byte(json)
|
||||||
ioutil.WriteFile("feed.json", json_byte, 0644)
|
ioutil.WriteFile("feed.json", json_byte, 0644)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
/* webserver.go
|
/* webserver.go
|
||||||
*
|
*
|
||||||
* This is the webserver handler for Pogo, and handles
|
* This is the webserver handler for Pogo, and handles
|
||||||
* all incoming connections, including authentication.
|
* all incoming connections, including authentication.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/subtle"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"crypto/subtle"
|
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
@ -43,13 +43,13 @@ func JsonHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
// Serve up homepage
|
// Serve up homepage
|
||||||
func HomeHandler(w http.ResponseWriter, r *http.Request) {
|
func HomeHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
data, err := ioutil.ReadFile("assets/index.html")
|
data, err := ioutil.ReadFile("assets/1index.html")
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
w.Write(data)
|
w.Write(data)
|
||||||
} else {
|
} else {
|
||||||
w.WriteHeader(500)
|
w.WriteHeader(500)
|
||||||
w.Write([]byte("500 Something went wrong - " + http.StatusText(500)))
|
w.Write([]byte("Error500 - " + http.StatusText(500)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,22 +60,22 @@ func HomeHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
* Code from stackoverflow by user Timmmm
|
* Code from stackoverflow by user Timmmm
|
||||||
* https://stackoverflow.com/questions/21936332/idiomatic-way-of-requiring-http-basic-auth-in-go/39591234#39591234
|
* https://stackoverflow.com/questions/21936332/idiomatic-way-of-requiring-http-basic-auth-in-go/39591234#39591234
|
||||||
*/
|
*/
|
||||||
func BasicAuth(handler http.HandlerFunc,) http.HandlerFunc {
|
func BasicAuth(handler http.HandlerFunc) http.HandlerFunc {
|
||||||
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
username := viper.GetString("AdminUsername")
|
username := viper.GetString("AdminUsername")
|
||||||
password := viper.GetString("AdminPassword")
|
password := viper.GetString("AdminPassword")
|
||||||
realm := "Login to Pogo admin interface"
|
realm := "Login to Pogo admin interface"
|
||||||
user, pass, ok := r.BasicAuth()
|
user, pass, ok := r.BasicAuth()
|
||||||
|
|
||||||
if !ok || subtle.ConstantTimeCompare([]byte(user), []byte(username)) != 1 || subtle.ConstantTimeCompare([]byte(pass), []byte(password)) != 1 {
|
if !ok || subtle.ConstantTimeCompare([]byte(user), []byte(username)) != 1 || subtle.ConstantTimeCompare([]byte(pass), []byte(password)) != 1 {
|
||||||
w.Header().Set("WWW-Authenticate", `Basic realm="`+realm+`"`)
|
w.Header().Set("WWW-Authenticate", `Basic realm="`+realm+`"`)
|
||||||
w.WriteHeader(401)
|
w.WriteHeader(401)
|
||||||
w.Write([]byte("Unauthorised.\n"))
|
w.Write([]byte("Unauthorised.\n"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
handler(w, r)
|
handler(w, r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handler for serving up admin page
|
// Handler for serving up admin page
|
||||||
|
@ -95,12 +95,12 @@ func main() {
|
||||||
viper.SetConfigName("config")
|
viper.SetConfigName("config")
|
||||||
viper.AddConfigPath(".")
|
viper.AddConfigPath(".")
|
||||||
err := viper.ReadInConfig() // Find and read the config file
|
err := viper.ReadInConfig() // Find and read the config file
|
||||||
if err != nil { // Handle errors reading the config file
|
if err != nil { // Handle errors reading the config file
|
||||||
panic(fmt.Errorf("Fatal error config file: %s \n", err))
|
panic(fmt.Errorf("Fatal error config file: %s \n", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start the watch() function in generate_rss.go, which
|
// Start the watch() function in generate_rss.go, which
|
||||||
// watches for file changes and regenerates the feed
|
// watches for file changes and regenerates the feed
|
||||||
go watch()
|
go watch()
|
||||||
|
|
||||||
// Define routes
|
// Define routes
|
||||||
|
|
Loading…
Reference in a new issue