Reste à prévoir la pagination et la recherche
This commit is contained in:
33
web.go
33
web.go
@@ -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
|
||||
}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user