30
main.go
30
main.go
@@ -2,8 +2,12 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"nextbook/pkg/storygraph"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
@@ -23,16 +27,26 @@ func init() {
|
||||
}
|
||||
|
||||
func main() {
|
||||
go updateWorker()
|
||||
latestBooks := map[string]*storygraph.Book{}
|
||||
go func() {
|
||||
var err error
|
||||
for {
|
||||
latestBooks, err = storygraph.GetLatestBooks()
|
||||
if err != nil {
|
||||
fmt.Println("Error fetching latest books:", err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("Updated latest book recommendations")
|
||||
|
||||
time.Sleep(1 * time.Hour)
|
||||
}
|
||||
}()
|
||||
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
tmpl := template.Must(template.ParseFiles("templates/index.html"))
|
||||
tmpl.Execute(w, latestBooks)
|
||||
})
|
||||
|
||||
http.Handle("/assets/", http.StripPrefix("/assets/", http.FileServer(http.Dir("assets"))))
|
||||
http.ListenAndServe(fmt.Sprintf(":%s", port), nil)
|
||||
}
|
||||
|
||||
func updateWorker() {
|
||||
// TODO: Update worker
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user