Same changes
This commit is contained in:
39
main.go
39
main.go
@@ -6,21 +6,30 @@ import (
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/mmcdole/gofeed"
|
||||
"wire/internal/api"
|
||||
"wire/internal/config"
|
||||
)
|
||||
|
||||
//go:embed version
|
||||
var version string
|
||||
|
||||
type Data struct {
|
||||
Version string
|
||||
Articles []Article
|
||||
Version string
|
||||
Quote template.HTML
|
||||
Ramblings string
|
||||
Articles []Article
|
||||
Config config.Config
|
||||
}
|
||||
|
||||
type Article struct {
|
||||
Title string
|
||||
Link string
|
||||
Link string
|
||||
}
|
||||
|
||||
type Quote struct {
|
||||
Q string `json:"q"`
|
||||
A string `json:"a"`
|
||||
H string `json:"h"`
|
||||
}
|
||||
|
||||
var data Data = Data{
|
||||
@@ -30,20 +39,24 @@ var data Data = Data{
|
||||
func main() {
|
||||
http.HandleFunc("/", newsHandler)
|
||||
|
||||
fp := gofeed.NewParser()
|
||||
feed, _ := fp.ParseURL("https://rss.nytimes.com/services/xml/rss/nyt/US.xml")
|
||||
cfg := config.NewConfig()
|
||||
cfg.ReadConfig()
|
||||
data.Config = cfg
|
||||
|
||||
for i, v := range feed.Items {
|
||||
items, err := api.FetchRSS("https://rss.nytimes.com/services/xml/rss/nyt/US.xml")
|
||||
for _, v := range items {
|
||||
data.Articles = append(data.Articles, Article{
|
||||
Title: v.Title,
|
||||
Link: v.Link,
|
||||
Link: v.Link,
|
||||
})
|
||||
|
||||
if i == 9 {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
quote, err := api.FetchJSON[[]Quote]("https://zenquotes.io/api/today")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
data.Quote = template.HTML(quote[0].H)
|
||||
|
||||
fmt.Println("wire: starting server at http://127.0.0.1:1337")
|
||||
log.Fatal(http.ListenAndServe("127.0.0.1:1337", nil))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user