I'm following the golang.org tutorial on building a wiki page (https://golang.org/doc/articles/wiki/#tmp_4) and everything runs fine until I've gotten the above error message during step "Using net/http to serve wiki pages". I've got a text.txt file in src/github.com/user/gowiki/test.txt but loadPage(title) doesn't seem to be accessing the test.txt file. Any help is greatly appreciated. Thanks!
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
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
}
func viewHandler(w http.ResponseWriter, r *http.Request) {
title := r.URL.Path[len("/view/"):]
p, _ := loadPage(title)
fmt.Fprintf(w, "<h1>%s</h1><div>%s</div>", p.Title, p.Body)
}
func main() {
http.HandleFunc("/view/", viewHandler)
http.ListenAndServe(":8080", nil)
}