2024-12-20 01:15:56 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
2024-12-30 15:45:40 +01:00
|
|
|
//"fmt"
|
|
|
|
|
"crowsnest/internal/data"
|
|
|
|
|
"crowsnest/internal/model"
|
|
|
|
|
"fmt"
|
|
|
|
|
"html/template"
|
|
|
|
|
"net/http"
|
2024-12-20 01:15:56 +01:00
|
|
|
)
|
|
|
|
|
|
2024-12-30 15:45:40 +01:00
|
|
|
func index(w http.ResponseWriter, req *http.Request) {
|
|
|
|
|
fds, _ := data.NewFileDatastore("./persistence/spiegel100.json")
|
|
|
|
|
|
|
|
|
|
repo, _ := data.NewDefaultRepository[*model.Article](fds, "article")
|
|
|
|
|
articles, _ := repo.GetAll()
|
2024-12-20 01:15:56 +01:00
|
|
|
|
2024-12-30 15:45:40 +01:00
|
|
|
t := template.Must(template.ParseFiles("templates/article.html", "templates/layout.html"))
|
|
|
|
|
_ = t.ExecuteTemplate(w, "base", articles)
|
2024-12-27 22:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
2024-12-20 01:15:56 +01:00
|
|
|
func main() {
|
2024-12-30 15:45:40 +01:00
|
|
|
// routes
|
|
|
|
|
http.HandleFunc("/", index)
|
2024-12-20 01:15:56 +01:00
|
|
|
|
2024-12-30 15:45:40 +01:00
|
|
|
// serve files from the "static" directory
|
2024-12-20 01:15:56 +01:00
|
|
|
fs := http.FileServer(http.Dir("./static"))
|
2024-12-30 15:45:40 +01:00
|
|
|
http.Handle("/static", http.StripPrefix("/", fs))
|
2024-12-20 01:15:56 +01:00
|
|
|
|
2024-12-30 15:45:40 +01:00
|
|
|
t := template.Must(template.ParseFiles("templates/article.html"))
|
|
|
|
|
fmt.Println(t)
|
2024-12-27 03:25:44 +01:00
|
|
|
|
2024-12-30 15:45:40 +01:00
|
|
|
// start server
|
|
|
|
|
http.ListenAndServe(":8080", nil)
|
2024-12-20 01:15:56 +01:00
|
|
|
}
|