Beispiel #1
0
// 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)
}
Beispiel #2
0
func init() {
	config.ContentPath = "content/"
	config.TemplatePath = "template/"
	s, err := blog.NewServer(config)
	if err != nil {
		panic(err)
	}
	http.Handle("/", s)
}
Beispiel #3
0
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))
}