Пример #1
0
func showPage(page Page, w http.ResponseWriter, r *http.Request) {
	out, err := webshell.BuildTemplate(home_template, page)
	if err != nil {
		webshell.Error500(err.Error(), "text/plain", w, r)
	} else {
		w.Write(out)
	}
}
Пример #2
0
func Template(tplSource string, w http.ResponseWriter, r *http.Request) *template.Template {
	t := template.New("page")
	t, err := t.Parse(tplSource)
	if err != nil {
		webshell.Error500(err.Error(), "text/plain", w, r)
		return nil
	}
	return t
}
Пример #3
0
func tpl_error(w http.ResponseWriter, r *http.Request) {
	var page struct {
		Nonsense string
	}
	out, err := webshell.ServeTemplateFile("templates/test.html", page)
	if err != nil {
		fmt.Println("[!] error")
		webshell.Error500(err.Error(), "text/plain", w, r)
	} else {
		w.Write(out)
	}
}
Пример #4
0
func tpl_test2(w http.ResponseWriter, r *http.Request) {
	var page struct {
		Title     string
		Paragraph string
	}
	page.Title = "another test page"
	page.Paragraph = "Sæmundar Edda"
	out, err := webshell.ServeTemplateFile("templates/test.html", page)
	if err != nil {
		webshell.Error500(err.Error(), "text/plain", w, r)
	} else {
		w.Write(out)
	}
}
Пример #5
0
func tpl_test(w http.ResponseWriter, r *http.Request) {
	var page struct {
		Title     string
		Paragraph string
	}
	page.Title = "test page"
	page.Paragraph = "rw nw prt m hrw"
	out, err := webshell.BuildTemplateFile("templates/test.html", page)
	if err != nil {
		webshell.Error500(err.Error(), "text/plain", w, r)
	} else {
		w.Write(out)
	}
}
Пример #6
0
func servePage(w http.ResponseWriter, r *http.Request) {
	md_file := getMdFilename(r.URL.Path[1:])
	title := getPageTitle(md_file)
	out, err := loadMarkdown(md_file)
	if err != nil {
		webshell.Error404("Page not found.", "text/plain", w, r)
		return
	}
	page := Page{false, false, title, template.HTML(string(out))}
	active := extRegex.ReplaceAllString(filepath.Base(md_file), "$1")
	if active == "index" {
		page.HomeActive = true
	} else if active == "about" {
		page.AboutActive = true
	}
	body, err := webshell.BuildTemplate(page_tpl, page)
	if err != nil {
		webshell.Error500(err.Error(), "text/plain", w, r)
		return
	}
	w.Write(body)
}