From 80dd22004b8506467bf4eea9764629155138810c Mon Sep 17 00:00:00 2001 From: gmemstr Date: Sat, 1 Jul 2017 23:59:59 -0700 Subject: [PATCH] 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. --- feed.json | 15 ++++++++++----- feed.rss | 19 ++++++++++--------- generate_rss.go | 34 +++++++++++++--------------------- 3 files changed, 33 insertions(+), 35 deletions(-) diff --git a/feed.json b/feed.json index e93a407..3eca1c3 100644 --- a/feed.json +++ b/feed.json @@ -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" + } } ] } \ No newline at end of file diff --git a/feed.rss b/feed.rss index 2579646..cbdc737 100644 --- a/feed.rss +++ b/feed.rss @@ -1,19 +1,20 @@ - - + Git Galaxy Stargazers + http://podcast.gitgalaxy.com discussion about open source projects - Sat, 01 Jul 2017 00:23:10 -0700 + gabriel@gitgalaxy.com (Gabriel Simmer) + Sat, 01 Jul 2017 23:35:38 -0700 - - - + http://podcast.gitgalaxy.com/assets/podcast_image.png + http://podcast.gitgalaxy.com/assets/podcast_image.png + http://podcast.gitgalaxy.com/assets/podcast_image.png TESTING WORLD - /download/2017-07-12_TESTING WORLD.mp3 - testing4 - + http://podcast.gitgalaxy.com/download/2017-07-12_TESTING WORLD.mp3 + 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. + Wed, 12 Jul 2017 00:00:00 +0000 diff --git a/generate_rss.go b/generate_rss.go index 536ebf7..6c4e1d4 100644 --- a/generate_rss.go +++ b/generate_rss.go @@ -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, }, }