Reste à prévoir la pagination et la recherche

This commit is contained in:
Laurent Ulrich
2025-08-20 16:19:55 +02:00
parent 10ebdaad4a
commit 9dd396e95f
8 changed files with 183 additions and 70 deletions

33
web.go
View File

@@ -3,14 +3,17 @@ package main
import (
"html/template"
"log"
"net"
"net/http"
)
func StartServer(blog *Blog) {
func StartServer(configuration BlogConfiguration, blog *Blog) {
mux := http.NewServeMux()
/* Handle home page (/): list of blog entries */
http.HandleFunc("GET /{$}",
mux.HandleFunc("GET /{$}",
func(w http.ResponseWriter, r *http.Request) {
log.Printf("%+v", r.Header)
tpl, err := template.New("index").Parse(indexTemplate)
if err != nil {
log.Fatal(err)
@@ -24,7 +27,7 @@ func StartServer(blog *Blog) {
})
/* Handle one post display(/post/{post ID}) */
http.HandleFunc("GET /post/{id}",
mux.HandleFunc("GET /post/{id}",
func(w http.ResponseWriter, r *http.Request) {
id := r.PathValue("id")
post, found := blog.GetPost(id)
@@ -42,11 +45,31 @@ func StartServer(blog *Blog) {
})
http.HandleFunc("GET /favicon.ico",
mux.HandleFunc("GET /styles.css",
func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "text/css")
w.Write([]byte(nativeCSS))
})
mux.HandleFunc("GET /favicon.ico",
func(w http.ResponseWriter, r *http.Request) {
log.Println("favicon.ico")
w.WriteHeader(200)
})
http.ListenAndServe("0.0.0.0:8080", nil)
addr := net.JoinHostPort(configuration.Service.Address, configuration.Service.Port)
server := &http.Server{
Addr: addr,
Handler: mux,
}
server.ListenAndServe()
//http.ListenAndServe(addr, server)
}
/*
func isCodeServerProxy(r *http.Request) bool {
return len(r.Header.Get("code-server-session")) > 0
}
*/