Ramblings
This commit is contained in:
16
main.go
16
main.go
@@ -10,6 +10,7 @@ import (
|
||||
"wire/internal/api"
|
||||
"wire/internal/articles"
|
||||
"wire/internal/config"
|
||||
"wire/internal/ramblings"
|
||||
)
|
||||
|
||||
//go:embed version
|
||||
@@ -20,7 +21,7 @@ var verboseFlag = flag.Bool("verbose", false, "Enable verbose logging")
|
||||
type Data struct {
|
||||
Version string
|
||||
Quote template.HTML
|
||||
Ramblings string
|
||||
Ramblings ramblings.Ramblings
|
||||
Articles articles.Articles
|
||||
Config config.Config
|
||||
}
|
||||
@@ -42,22 +43,29 @@ func main() {
|
||||
cfg.ReadConfig()
|
||||
data.Config = cfg
|
||||
|
||||
ap := articles.NewParser("https://rss.nytimes.com/services/xml/rss/nyt/US.xml")
|
||||
ap := articles.NewParser(cfg.Articles_Path)
|
||||
data.Articles = ap.GetArticles()
|
||||
|
||||
rp := ramblings.NewParser(cfg.Ramblings_Path)
|
||||
data.Ramblings = rp.GetRamblings()
|
||||
|
||||
for _, ramble := range rp.GetRamblings() {
|
||||
http.HandleFunc("/" + ramble.Link, ramblings.NewHandler(ramble))
|
||||
}
|
||||
|
||||
quote, err := api.FetchJSON[[]Quote]("https://zenquotes.io/api/today")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
data.Quote = template.HTML(quote[0].H)
|
||||
|
||||
http.HandleFunc("/", newsHandler)
|
||||
http.HandleFunc("/", mainHandler)
|
||||
|
||||
fmt.Println("wire: starting server at http://127.0.0.1:1337")
|
||||
log.Fatal(http.ListenAndServe("127.0.0.1:1337", nil))
|
||||
}
|
||||
|
||||
func newsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
func mainHandler(w http.ResponseWriter, r *http.Request) {
|
||||
tmpl := template.Must(template.ParseFiles("templates/main.html"))
|
||||
|
||||
tmpl.ExecuteTemplate(w, "main.html", data)
|
||||
|
||||
Reference in New Issue
Block a user