It is straightforward to serve static pages with Go or config file on App Engine, but how to serve static pages on App Engine with Go?
I got the following error when I tried to customize the 404 page with Go:
No such file or directory
The solution turns out to be simple: do not do both.
The file will not be accessible to Go if there is already a rule for it in config.yaml. Remove the rule from config.yaml and the file will be available to Go again (source: google-appengine-go).
Here is an exmaple to serve a custom 404 not found page:
func serve404(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotFound)
f, err := http.Dir("public").Open("404.html")
if err != nil {
serveError(w, r, err)
return
}
defer f.Close()
io.Copy(w, f)
}