// reloadingBlogServer is an handler that restarts the blog server on each page // view. Inefficient; don't enable by default. Handy when editing blog content. func reloadingBlogServer(w http.ResponseWriter, r *http.Request) { s, err := blog.NewServer(config) if err != nil { http.Error(w, err.Error(), 500) return } s.ServeHTTP(w, r) }
func init() { config.ContentPath = "content/" config.TemplatePath = "template/" s, err := blog.NewServer(config) if err != nil { panic(err) } http.Handle("/", s) }
func main() { flag.Parse() config.ContentPath = *contentPath config.TemplatePath = *templatePath if *reload { http.HandleFunc("/", reloadingBlogServer) } else { s, err := blog.NewServer(config) if err != nil { log.Fatal(err) } http.Handle("/", s) } fs := http.FileServer(http.Dir(*staticPath)) http.Handle("/static/", http.StripPrefix("/static/", fs)) log.Fatal(http.ListenAndServe(*httpAddr, nil)) }