Start refactor
This commit is contained in:
24
main.go
24
main.go
@@ -2,30 +2,29 @@ package main
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"flag"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
"wire/internal/api"
|
||||
"wire/internal/articles"
|
||||
"wire/internal/config"
|
||||
)
|
||||
|
||||
//go:embed version
|
||||
var version string
|
||||
|
||||
var verboseFlag = flag.Bool("verbose", false, "Enable verbose logging")
|
||||
|
||||
type Data struct {
|
||||
Version string
|
||||
Quote template.HTML
|
||||
Ramblings string
|
||||
Articles []Article
|
||||
Articles articles.Articles
|
||||
Config config.Config
|
||||
}
|
||||
|
||||
type Article struct {
|
||||
Title string
|
||||
Link string
|
||||
}
|
||||
|
||||
type Quote struct {
|
||||
Q string `json:"q"`
|
||||
A string `json:"a"`
|
||||
@@ -37,19 +36,14 @@ var data Data = Data{
|
||||
}
|
||||
|
||||
func main() {
|
||||
http.HandleFunc("/", newsHandler)
|
||||
flag.Parse()
|
||||
|
||||
cfg := config.NewConfig()
|
||||
cfg.ReadConfig()
|
||||
data.Config = cfg
|
||||
|
||||
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,
|
||||
})
|
||||
}
|
||||
ap := articles.NewParser("https://rss.nytimes.com/services/xml/rss/nyt/US.xml")
|
||||
data.Articles = ap.GetArticles()
|
||||
|
||||
quote, err := api.FetchJSON[[]Quote]("https://zenquotes.io/api/today")
|
||||
if err != nil {
|
||||
@@ -57,6 +51,8 @@ func main() {
|
||||
}
|
||||
data.Quote = template.HTML(quote[0].H)
|
||||
|
||||
http.HandleFunc("/", newsHandler)
|
||||
|
||||
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