Reorganizing file directory structure to match other Golang projects

This commit is contained in:
gmemstr 2017-09-25 11:22:30 -07:00
parent 019e303b3b
commit 4dd25948f6
260 changed files with 105 additions and 88 deletions

View file

@ -18,3 +18,5 @@ feed\.json
podcasts/ podcasts/
feed\.rss feed\.rss
.travis\.yml

View file

@ -18,7 +18,8 @@ RUN apt update; apt install build-essential -y && \
make linux && chmod +x whiterabbit && \ make linux && chmod +x whiterabbit && \
ls -al && \ ls -al && \
mkdir podcasts && \ mkdir podcasts && \
touch feed.rss feed.json && echo '{}' >feed.json touch assets/web/feed.rss assets/web/feed.json && \
echo '{}' >assets/web/feed.json
EXPOSE 8000 EXPOSE 8000

View file

@ -1,5 +1,5 @@
{ {
"ImportPath": "podcast/src", "ImportPath": "podcast",
"GoVersion": "go1.8", "GoVersion": "go1.8",
"GodepVersion": "v79", "GodepVersion": "v79",
"Deps": [ "Deps": [

View file

View file

@ -1,11 +1,11 @@
all: all:
go build src/webserver.go src/admin.go src/generate_rss.go src/setup.go src/configreader.go go build webserver.go admin.go generate_rss.go setup.go configreader.go
windows: src/admin.go src/webserver.go src/generate_rss.go windows: admin.go webserver.go generate_rss.go
go build -o pogoapp.exe src/webserver.go src/admin.go src/generate_rss.go src/setup.go go build -o pogoapp.exe webserver.go admin.go generate_rss.go setup.go
linux: src/admin.go src/webserver.go src/generate_rss.go linux: admin.go webserver.go generate_rss.go
go build -o pogoapp src/webserver.go src/admin.go src/generate_rss.go src/setup.go go build -o pogoapp webserver.go admin.go generate_rss.go setup.go
install: install:
go get github.com/gmemstr/feeds go get github.com/gmemstr/feeds
@ -17,5 +17,5 @@ docker:
docker build . docker build .
and run: and run:
go build src/webserver.go src/admin.go src/generate_rss.go src/setup.go go build webserver.go admin.go generate_rss.go setup.go
./pogoapp.exe ./pogoapp.exe

View file

@ -23,7 +23,7 @@ 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/web/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>"))
@ -32,7 +32,7 @@ func CustomCss(w http.ResponseWriter, r *http.Request) {
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/web/static/custom.css")
if err != nil { if err != nil {
panic(err) panic(err)
} else { } else {

View file

@ -0,0 +1,19 @@
/*
* This is the file of custom CSS styling that
* can be set by the publisher.
*
* If you're writing the custom CSS, please see the reference:
* https://github.com/gmemstr/Pogo/wiki/Custom-CSS/
*/
.container {} /* Basic container from styles.css */
.title {} /* Page title */
.adminlink {} /* Link to admin interface */
.podcastlist {} /* Chronological podcast list */
.podcastitem {} /* Single podcast item (group of elements) */
.podcasttitle {} /* Title of podcast item */
.podcastdate {} /* Date podcast item was published */
.podcastdesc {} /* Podcast item description */
.podcastaudio {} /* Podcast <audio> tag */

View file

@ -1,9 +0,0 @@
{
"MediaDirectory": "podcasts/",
"Name": "Pogo Test Feed",
"Host": "Gabriel Simmer",
"Email": "admin@localhost",
"Description": "Discussion about open source projects on the internet.",
"Image": "localhost:8000/assets/podcast_image.png",
"PodcastUrl": "http://localhost:8000"
}

61
configreader.go Normal file
View file

@ -0,0 +1,61 @@
package main
import (
"encoding/json"
"io/ioutil"
)
// Configuration structure
type Config struct {
Name string
Host string
Email string
Description string
Image string
PodcastUrl string
}
// Single use structure
type User struct {
Username string
Hash string
}
// Read config file and make values accesible
func ReadConfig() Config {
// Read config.json
d, err := ioutil.ReadFile("assets/config/config.json")
if err != nil {
panic(err)
}
var c Config // Unmarshal json
err = json.Unmarshal(d, &c)
if err != nil {
panic(err)
}
return c
}
// Return single users username & passsword *hash*
func GetUser(username string) (usr string, pwd string) {
// Read users json file
d, err := ioutil.ReadFile("assets/config/users.json")
if err != nil {
panic(err)
}
var u interface{}
err = json.Unmarshal(d, &u) // Unmarshal into interface
// Iterate through map until we find matching username
users := u.(map[string]interface{})
for k, v := range users {
if k == username {
usr = k
pwd = v.(string)
}
}
return // Returns k & v values, aka username and password *hash*
}

View file

@ -35,8 +35,6 @@ func watch() {
case event := <-watcher.Events: case event := <-watcher.Events:
// log.Println("event:", event) // log.Println("event:", event)
if event.Op&fsnotify.Write == fsnotify.Write { if event.Op&fsnotify.Write == fsnotify.Write {
// log.Println("modified file:", event.Name)
log.Println("File up(load/date)ed: ", event.Name)
generate_rss() generate_rss()
} }
case err := <-watcher.Errors: case err := <-watcher.Errors:
@ -49,7 +47,7 @@ func watch() {
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
err = watcher.Add("config.json") err = watcher.Add("assets/config/config.json")
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@ -118,8 +116,8 @@ func generate_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("assets/web/feed.rss", rss_byte, 0644)
json_byte := []byte(json) json_byte := []byte(json)
ioutil.WriteFile("feed.json", json_byte, 0644) ioutil.WriteFile("assets/web/feed.json", json_byte, 0644)
} }

View file

@ -3,7 +3,6 @@ package main
import ( import (
"io/ioutil" "io/ioutil"
"net/http" "net/http"
// "fmt"
"encoding/json" "encoding/json"
"strings" "strings"
) )
@ -20,7 +19,7 @@ type NewConfig struct {
// Serve setup.html and config parameters // Serve setup.html and config parameters
func ServeSetup(w http.ResponseWriter, r *http.Request) { func ServeSetup(w http.ResponseWriter, r *http.Request) {
if r.Method == "GET" { if r.Method == "GET" {
data, err := ioutil.ReadFile("assets/setup.html") data, err := ioutil.ReadFile("assets/web/setup.html")
if err != nil { if err != nil {
panic(err) panic(err)
@ -36,8 +35,8 @@ func ServeSetup(w http.ResponseWriter, r *http.Request) {
strings.Join(r.Form["podcasthost"], ""), // Podcast host strings.Join(r.Form["podcasthost"], ""), // Podcast host
strings.Join(r.Form["podcastemail"], ""), // Podcast host email strings.Join(r.Form["podcastemail"], ""), // Podcast host email
strings.Join(r.Form["podcastdescription"], ""), // Podcast Description strings.Join(r.Form["podcastdescription"], ""), // Podcast Description
"", // Podcast image "", // Podcast image
"", // Podcast location "", // Podcast location
} }
b, err := json.Marshal(cnf) b, err := json.Marshal(cnf)
@ -45,7 +44,7 @@ func ServeSetup(w http.ResponseWriter, r *http.Request) {
panic(err) panic(err)
} }
ioutil.WriteFile("config.json", b, 0644) ioutil.WriteFile("assets/config/config.json", b, 0644)
w.Write([]byte("Done")) w.Write([]byte("Done"))
} }
} }

View file

@ -1,54 +0,0 @@
package main
import (
"encoding/json"
"io/ioutil"
)
type Config struct {
Name string
Host string
Email string
Description string
Image string
PodcastUrl string
}
type User struct {
Username string
Hash string
}
func ReadConfig() Config {
d, err := ioutil.ReadFile("config.json")
if err != nil {
panic(err)
}
var c Config
err = json.Unmarshal(d, &c)
if err != nil {
panic(err)
}
return c
}
func GetUser(username string) (usr string, pwd string) {
d, err := ioutil.ReadFile("users.json")
if err != nil {
panic(err)
}
var u interface{}
err = json.Unmarshal(d, &u)
users := u.(map[string]interface{})
for k, v := range users {
if k == username {
usr = k
pwd = v.(string)
}
}
return
}

Some files were not shown because too many files have changed in this diff Show more