Initial release

Signed-off-by: Marcus Noble <github@marcusnoble.co.uk>
This commit is contained in:
2025-05-02 14:36:51 +01:00
parent 866cbaa42f
commit 9d4f5d8cba
8 changed files with 1215 additions and 10 deletions

30
main.go
View File

@@ -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
}