Files
crowsnest/cmd/frontend/main.go

36 lines
862 B
Go
Raw Normal View History

2024-12-20 01:15:56 +01:00
package main
import (
//"fmt"
"crowsnest/internal/data"
"crowsnest/internal/model"
"fmt"
"html/template"
"net/http"
2024-12-20 01:15:56 +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
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() {
// routes
http.HandleFunc("/", index)
2024-12-20 01:15:56 +01:00
// serve files from the "static" directory
2024-12-20 01:15:56 +01:00
fs := http.FileServer(http.Dir("./static"))
http.Handle("/static", http.StripPrefix("/", fs))
2024-12-20 01:15:56 +01:00
t := template.Must(template.ParseFiles("templates/article.html"))
fmt.Println(t)
2024-12-27 03:25:44 +01:00
// start server
http.ListenAndServe(":8080", nil)
2024-12-20 01:15:56 +01:00
}