コード例 #1
0
ファイル: post.go プロジェクト: francoishill/rsc
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)
}