func oldRedirect(ctxt *fs.Context, w http.ResponseWriter, req *http.Request, p string) { m := map[string]string{} if key, ok := ctxt.CacheLoad("blog:oldRedirectMap", "blog/post", &m); !ok { dir, err := ctxt.ReadDir("blog/post") if err != nil { panic(err) } for _, d := range dir { meta, _, err := loadPost(ctxt, d.Name, req) if err != nil { // Should not happen: we just listed the directory. panic(err) } m[meta.OldURL] = "/" + d.Name } ctxt.CacheStore(key, m) } if url, ok := m[p]; ok { http.Redirect(w, req, url, http.StatusFound) return } notfound(ctxt, w, req) }
func readDir(c *fs.Context, root string) ([]proto.FileInfo, error) { return c.ReadDir(root) }