gonfig -> viper for configuration file

Currently focusing on the RSS generation, JSON will come later - that is more aimed at the frontend or external apps. Have to have feeds fully validating on https://validator.w3.org/feed/ before being deemed "acceptable" and "production ready". Will be writing a lot of changes to my feeds fork, which will not be pulled into the main feeds repository.
This commit is contained in:
gmemstr 2017-07-01 23:59:59 -07:00
parent a78472364c
commit 80dd22004b
3 changed files with 33 additions and 35 deletions

View file

@ -1,16 +1,21 @@
{
"version": "https://jsonfeed.org/version/1",
"title": "",
"title": "Git Galaxy Stargazers",
"home_page_url": "https://podcast.gitgalaxy.com",
"description": "discussion about open source projects",
"author": {},
"author": {
"name": "Gabriel Simmer"
},
"items": [
{
"id": "",
"url": "/download/2017-07-12_TESTING WORLD.mp3",
"url": "https://podcast.gitgalaxy.com/download/2017-07-12_TESTING WORLD.mp3",
"title": "TESTING WORLD",
"summary": "testing4",
"summary": "In this episode, Gabriel discusses the format of the podcast, rambles about his complete lack of knowledge of Machine Learning, and covers a couple interesting Machine Learning centered projects.",
"date_published": "2017-07-12T00:00:00Z",
"author": {}
"author": {
"name": "Gabriel Simmer"
}
}
]
}

View file

@ -1,19 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?><rss version="2.0">
<channel>
<title></title>
<link></link>
<title>Git Galaxy Stargazers</title>
<link>http://podcast.gitgalaxy.com</link>
<description>discussion about open source projects</description>
<pubDate>Sat, 01 Jul 2017 00:23:10 -0700</pubDate>
<managingEditor>gabriel@gitgalaxy.com (Gabriel Simmer)</managingEditor>
<pubDate>Sat, 01 Jul 2017 23:35:38 -0700</pubDate>
<image>
<url></url>
<title></title>
<link></link>
<url>http://podcast.gitgalaxy.com/assets/podcast_image.png</url>
<title>http://podcast.gitgalaxy.com/assets/podcast_image.png</title>
<link>http://podcast.gitgalaxy.com/assets/podcast_image.png</link>
</image>
<item>
<title>TESTING WORLD</title>
<link>/download/2017-07-12_TESTING WORLD.mp3</link>
<description>testing4</description>
<enclosure url="/download/2017-07-12_TESTING WORLD.mp3" length="100" type="audio/mpeg"></enclosure>
<link>http://podcast.gitgalaxy.com/download/2017-07-12_TESTING WORLD.mp3</link>
<description>In this episode, Gabriel discusses the format of the podcast, rambles about his complete lack of knowledge of Machine Learning, and covers a couple interesting Machine Learning centered projects.</description>
<enclosure url="http://podcast.gitgalaxy.com/download/2017-07-12_TESTING WORLD.mp3" length="100" type="audio/mpeg"></enclosure>
<pubDate>Wed, 12 Jul 2017 00:00:00 +0000</pubDate>
</item>
</channel>

View file

@ -9,17 +9,9 @@ import (
"github.com/fsnotify/fsnotify"
"github.com/gmemstr/feeds"
"github.com/Tkanos/gonfig"
"github.com/spf13/viper"
)
type Configuration struct {
Name string
Host string
Email string
Image string
PodcastUrl string
}
func watch() {
watcher, err := fsnotify.NewWatcher()
if err != nil {
@ -51,12 +43,12 @@ func watch() {
}
func generate_rss() {
configuration := Configuration{}
err := gonfig.GetConf("config.json", &configuration)
if err != nil {
log.Fatal(err)
viper.SetConfigName("config")
viper.AddConfigPath(".")
err := viper.ReadInConfig() // Find and read the config file
if err != nil { // Handle errors reading the config file
panic(fmt.Errorf("Fatal error config file: %s \n", err))
}
fmt.Println(configuration)
now := time.Now()
files, err := ioutil.ReadDir("podcasts")
if err != nil {
@ -64,12 +56,12 @@ func generate_rss() {
}
feed := &feeds.Feed{
Title: configuration.Name,
Link: &feeds.Link{Href: configuration.PodcastUrl},
Title: viper.GetString("Name"),
Link: &feeds.Link{Href: viper.GetString("PodcastUrl")},
Description: "discussion about open source projects",
Author: &feeds.Author{Name: configuration.Host, Email: configuration.Email},
Author: &feeds.Author{Name: viper.GetString("Host"), Email:viper.GetString("Email")},
Created: now,
Image: &feeds.Image{Url: configuration.Image},
Image: &feeds.Image{Url: viper.GetString("Image")},
}
for _, file := range files {
@ -88,10 +80,10 @@ func generate_rss() {
feed.Items = []*feeds.Item{
&feeds.Item{
Title: title,
Link: &feeds.Link{Href: configuration.PodcastUrl + "/download/" + file.Name(), Length: "100", Type: "audio/mpeg"},
Enclosure: &feeds.Enclosure{Url: configuration.PodcastUrl + "/download/" + file.Name(), Length: "100", Type: "audio/mpeg"},
Link: &feeds.Link{Href: viper.GetString("PodcastUrl") + "/download/" + file.Name(), Length: "100", Type: "audio/mpeg"},
Enclosure: &feeds.Enclosure{Url: viper.GetString("PodcastUrl") + "/download/" + file.Name(), Length: "100", Type: "audio/mpeg"},
Description: string(description),
Author: &feeds.Author{Name: configuration.Host, Email: configuration.Email},
Author: &feeds.Author{Name: viper.GetString("Host"), Email: viper.GetString("Email")},
Created: date,
},
}