Ejemplo n.º 1
0
func check(err error) {
	switch err.(type) {
	case *os.PathError:
		logger.Log(logFile, err)
		if _, err := os.Stat(dataFile); os.IsNotExist(err) {
			os.Create(dataFile)
		}
	default:
		logger.Log(logFile, err)
	}
}
Ejemplo n.º 2
0
// Render the page to website.
func renderTemplate(w http.ResponseWriter, tmpl string, p *Page) {
	p.Static = staticURL
	tmplList := []string{"templates/base.html", fmt.Sprintf("templates/%s.html", tmpl)}
	t, err := template.ParseFiles(tmplList...)
	if err != nil {
		logger.Log(logFile, errors.New("Template parsing error: "+err.Error()))
	}
	err = t.Execute(w, p)
	if err != nil {
		logger.Log(logFile, errors.New("Template executing error: "+err.Error()))
	}
}
Ejemplo n.º 3
0
// StartWebsite should be started on it's own goroutine.
func StartWebsite(address string) {
	http.HandleFunc("/", home)
	http.HandleFunc("/about", about)
	http.HandleFunc(staticURL, staticHandler)
	logger.Log(logFile, http.ListenAndServe(address, nil))
}