go error: undefined: "html/template".ParseFile -
i have following error while compiling code "html/template undefined: "html/template".parsefile"
at string of source code "t, _ := template.parsefile("edit.html", nil)"
package main import ( "net/http" "io/ioutil" "html/template" ) type page struct { title string body []byte } func (p *page) save() error { filename := p.title + ".txt" return ioutil.writefile(filename, p.body, 0600) } func loadpage(title string) (*page, error) { filename := title + ".txt" body, err := ioutil.readfile(filename) if err != nil { return nil, err } return &page{title: title, body: body}, nil } const lenpath = len("/view/") func edithandler(w http.responsewriter, r *http.request) { title := r.url.path[lenpath:] p, err := loadpage(title) if err != nil { p = &page{title: title} } t, _ := template.parsefile("edit.html", nil) t.execute(p, w) } func main() { http.handlefunc("/edit/", edithandler) http.listenandserve(":8080", nil) }
help tp remove error.
it should template.parsefiles("edit.html")
plural not singular
Comments
Post a Comment