Run gofmt tool on source files

This commit is contained in:
gmemstr 2017-09-21 12:10:16 -07:00
parent 4727da5c8a
commit 18267d0362
3 changed files with 65 additions and 66 deletions

View file

@ -7,12 +7,12 @@
package main
import (
"net/http"
"fmt"
"strings"
"io/ioutil"
"io"
"io/ioutil"
"net/http"
"os" // ioOS?
"strings"
)
// Write custom CSS to disk or send it back to the client if GET
@ -23,7 +23,7 @@ func CustomCss(w http.ResponseWriter, r *http.Request) {
filename := "custom.css"
err := ioutil.WriteFile("./assets/static/" + filename, []byte(css), 0644)
err := ioutil.WriteFile("./assets/static/"+filename, []byte(css), 0644)
if err != nil {
w.Write([]byte("<script>window.location = '/admin#failed';</script>"))
@ -32,9 +32,9 @@ func CustomCss(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("<script>window.location = '/admin#cssupdated';</script>"))
}
} else {
css,err := ioutil.ReadFile("./assets/static/custom.css")
css, err := ioutil.ReadFile("./assets/static/custom.css")
if err != nil {
panic (err)
panic(err)
} else {
w.Write(css)
}
@ -49,7 +49,7 @@ func CreateEpisode(w http.ResponseWriter, r *http.Request) {
date := strings.Join(r.Form["date"], "")
title := strings.Join(r.Form["title"], "")
name := fmt.Sprintf("%v_%v", date, title)
name := fmt.Sprintf("%v_%v", date, title)
filename := name + ".mp3"
shownotes := name + "_SHOWNOTES.md"
fmt.Println(name)
@ -57,30 +57,30 @@ func CreateEpisode(w http.ResponseWriter, r *http.Request) {
fmt.Println(description)
// Finish building filenames
err := ioutil.WriteFile("./podcasts/" + shownotes, []byte(description), 0644)
if err != nil {
err := ioutil.WriteFile("./podcasts/"+shownotes, []byte(description), 0644)
if err != nil {
w.Write([]byte("<script>window.location = '/admin#failed';</script>"))
fmt.Println(err)
}
fmt.Println(err)
}
file, handler, err := r.FormFile("file")
if err != nil {
if err != nil {
w.Write([]byte("<script>window.location = '/admin#failed';</script>"))
fmt.Println(err)
return
}
defer file.Close()
fmt.Println(handler.Header)
f, err := os.OpenFile("./podcasts/"+filename, os.O_WRONLY|os.O_CREATE, 0666)
if err != nil {
fmt.Println(err)
return
}
defer file.Close()
fmt.Println(handler.Header)
f, err := os.OpenFile("./podcasts/"+filename, os.O_WRONLY|os.O_CREATE, 0666)
if err != nil {
w.Write([]byte("<script>window.location = '/admin#failed';</script>"))
fmt.Println(err)
return
}
defer f.Close()
io.Copy(f, file)
fmt.Println(err)
return
}
defer f.Close()
io.Copy(f, file)
w.Write([]byte("<script>window.location = '/admin#published';</script>"))
}
}
@ -90,7 +90,7 @@ func RemoveEpisode(w http.ResponseWriter, r *http.Request) {
// Remove MP3 first
r.ParseMultipartForm(32 << 20)
episode := strings.Join(r.Form["episode"],"")
episode := strings.Join(r.Form["episode"], "")
os.Remove(episode)
sn := strings.Replace(episode, ".mp3", "_SHOWNOTES.md", 2)
os.Remove(sn)

View file

@ -24,7 +24,7 @@ func watch() {
viper.SetConfigName("config")
viper.AddConfigPath(".")
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))
}
watcher, err := fsnotify.NewWatcher()
@ -63,14 +63,13 @@ func watch() {
<-done
}
// Called when a file has been created / changed, uses gorilla feeds
// fork to add items to feed object
func generate_rss() {
viper.SetConfigName("config")
viper.AddConfigPath(".")
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))
}
now := time.Now()
@ -84,7 +83,7 @@ func generate_rss() {
Title: viper.GetString("Name"),
Link: &feeds.Link{Href: podcasturl},
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,
Image: &feeds.Image{Url: viper.GetString("Image")},
}
@ -94,17 +93,17 @@ func generate_rss() {
s := strings.Split(file.Name(), "_")
t := strings.Split(s[1], ".")
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 {
log.Fatal(err)
}
log.Fatal(err)
}
date, err := time.Parse("2006-01-02", s[0])
if err != nil {
log.Fatal(err)
}
size := fmt.Sprintf("%d", file.Size())
link := podcasturl + "/download/" + file.Name()
feed.Add (
feed.Add(
&feeds.Item{
Title: title,
Link: &feeds.Link{Href: link, Length: size, Type: "audio/mpeg"},

View file

@ -7,11 +7,11 @@
package main
import (
"crypto/subtle"
"fmt"
"io/ioutil"
"log"
"net/http"
"crypto/subtle"
"github.com/gorilla/mux"
"github.com/spf13/viper"
@ -43,13 +43,13 @@ func JsonHandler(w http.ResponseWriter, r *http.Request) {
// Serve up homepage
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 {
w.Write(data)
} else {
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
* 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) {
username := viper.GetString("AdminUsername")
password := viper.GetString("AdminPassword")
realm := "Login to Pogo admin interface"
user, pass, ok := r.BasicAuth()
return func(w http.ResponseWriter, r *http.Request) {
username := viper.GetString("AdminUsername")
password := viper.GetString("AdminPassword")
realm := "Login to Pogo admin interface"
user, pass, ok := r.BasicAuth()
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.WriteHeader(401)
w.Write([]byte("Unauthorised.\n"))
return
}
handler(w, r)
}
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.WriteHeader(401)
w.Write([]byte("Unauthorised.\n"))
return
}
handler(w, r)
}
}
// Handler for serving up admin page
@ -95,7 +95,7 @@ func main() {
viper.SetConfigName("config")
viper.AddConfigPath(".")
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))
}