cmd/server/main.go (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
package main
import (
"fmt"
"log"
"net/http"
"os"
)
func handler(w http.ResponseWriter, r *http.Request) {
title := r.URL.Path[len("/"):]
if title == "" {
title = "index"
}
log.Print(title)
http.ServeFile(w, r, "html/"+title+".html")
}
func main() {
// generate blog pages
if len(os.Args) == 2 {
switch os.Args[1] {
case "init":
genSite()
return
case "blog":
generateBlog()
return
}
}
fs := http.FileServer(http.Dir("static"))
blogfs := http.FileServer(http.Dir("en/blog"))
http.Handle("/static/", http.StripPrefix("/static/", fs))
http.Handle("/attachments/", http.StripPrefix("/attachments/", blogfs))
http.HandleFunc("/", handler)
fmt.Println("Running on :8080")
log.Fatal(http.ListenAndServe("0.0.0.0:8080", nil))
}
|