diff options
Diffstat (limited to 'gopher.go')
-rw-r--r-- | gopher.go | 52 |
1 files changed, 26 insertions, 26 deletions
@@ -17,13 +17,13 @@ import ( // GopherRouter builds a router that will handle gopher requests in a directory of git repositories. // // The routes it defines are: -// / gophermap listing of the repositories in the directory -// /:repository gophermap overview of the repository -// /:repository/branches gophermap list of branches/head -// /:repository/tags gophermap listing of tags -// /:repository/refs/:ref gophermap overview of a ref -// /:repository/refs/:ref/tree gophermap listing of a ref's root directory -// /:repository/refs/:ref/tree/*path for directories: gophermap list of contents +// / .gph listing of the repositories in the directory +// /:repository .gph overview of the repository +// /:repository/branches .gph list of branches/head +// /:repository/tags .gph listing of tags +// /:repository/refs/:ref .gph overview of a ref +// /:repository/refs/:ref/tree .gph listing of a ref's root directory +// /:repository/refs/:ref/tree/*path for directories:.gph list of contents // for files: raw files (guessed item type text/binary/image/etc) // /:repository/diffstat/:fromref/:toref text diffstat between two refs // /:repository/diff/:fromref/:toref text diff between two refs @@ -31,15 +31,15 @@ import ( // The overrides argument can provide templates to define the behavior of nearly all of the above routes. // All of them have default implementations, so the argument can be nil, but otherwise the template names // used are: -// repo_root.gophermap gophermap at / -// repo_home.gophermap gophermap at /:repository -// branch_list.gophermap gophermap at /:repository/branches -// tag_list.gophermap gophermap at /:repository/tags -// ref.gophermap gophermap at /:repository/refs/:ref -// tree.gophermap gophermap at direcotry paths under /:repository/refs/:ref/tree/*path -// (file paths return the raw files without any template involved) -// diffstat.gophertext plain text diffstat at /:repository/diffstat/:fromref/:toref -// diff.gophertext plain text diff at /:repository/diff/:fromref/:toref +// repo_root.gph gophermap at / +// repo_home.gph gophermap at /:repository +// branch_list.gph gophermap at /:repository/branches +// tag_list.gph gophermap at /:repository/tags +// ref.gph gophermap at /:repository/refs/:ref +// tree.gph gophermap at direcotry paths under /:repository/refs/:ref/tree/*path +// (file paths return the raw files without any template involved) +// diffstat.gph.txt plain text diffstat at /:repository/diffstat/:fromref/:toref +// diff.gph.txt plain text diff at /:repository/diff/:fromref/:toref // // Most of the templates above are rendered with an object with 6 fields: // Ctx: the context.Context from the request @@ -49,7 +49,7 @@ import ( // Port: the port number of the running server // Selector: the selector in the current request // -// The only exception is repo_root.gophermap, which is instead rendered with a slice of the repo names. +// The only exception is repo_root.gph, which is instead rendered with a slice of the repo names. // // All templates have 3 additional functions made available to them: // combine: func(string, ...string) string - successively combines paths using url.URL.ResolveReference @@ -63,17 +63,17 @@ func GopherRouter(repodir string, overrides *template.Template) *sliderule.Route repoRouter := &sliderule.Router{} repoRouter.Use(assignRepo(repodir)) - repoRouter.Route("/branches", runGopherTemplate(tmpl, "branch_list.gophermap", gopher.MenuType)) - repoRouter.Route("/tags", runGopherTemplate(tmpl, "tag_list.gophermap", gopher.MenuType)) - repoRouter.Route("/refs/:ref", runGopherTemplate(tmpl, "ref.gophermap", gopher.MenuType)) + repoRouter.Route("/branches", runGopherTemplate(tmpl, "branch_list.gph", gopher.MenuType)) + repoRouter.Route("/tags", runGopherTemplate(tmpl, "tag_list.gph", gopher.MenuType)) + repoRouter.Route("/refs/:ref", runGopherTemplate(tmpl, "ref.gph", gopher.MenuType)) repoRouter.Route("/refs/:ref/tree", gopherTreePath(tmpl, false)) repoRouter.Route("/refs/:ref/tree/*path", gopherTreePath(tmpl, true)) - repoRouter.Route("/diffstat/:fromref/:toref", runGopherTemplate(tmpl, "diffstat.gophertext", gopher.TextFileType)) - repoRouter.Route("/diff/:fromref/:toref", runGopherTemplate(tmpl, "diff.gophertext", gopher.TextFileType)) + repoRouter.Route("/diffstat/:fromref/:toref", runGopherTemplate(tmpl, "diffstat.gph.txt", gopher.TextFileType)) + repoRouter.Route("/diff/:fromref/:toref", runGopherTemplate(tmpl, "diff.gph.txt", gopher.TextFileType)) router := &sliderule.Router{} router.Route("/", gopherRoot(repodir, tmpl)) - router.Route("/:"+reponamekey, assignRepo(repodir)(runGopherTemplate(tmpl, "repo_home.gophermap", gopher.MenuType))) + router.Route("/:"+reponamekey, assignRepo(repodir)(runGopherTemplate(tmpl, "repo_home.gph", gopher.MenuType))) router.Mount("/:"+reponamekey, repoRouter) return router @@ -100,7 +100,7 @@ func gopherRoot(repodir string, tmpl *template.Template) sliderule.Handler { "Port": request.Port(), "Selector": request.Path, } - if err := tmpl.ExecuteTemplate(buf, "repo_root.gophermap", obj); err != nil { + if err := tmpl.ExecuteTemplate(buf, "repo_root.gph", obj); err != nil { return gopher.Error(err).Response() } @@ -126,7 +126,7 @@ func gopherTreePath(tmpl *template.Template, haspath bool) sliderule.Handler { if !haspath { params["path"] = "" } - return runGopherTemplate(tmpl, "tree.gophermap", gopher.MenuType).Handle(ctx, request) + return runGopherTemplate(tmpl, "tree.gph", gopher.MenuType).Handle(ctx, request) } body, err := repo.Blob(ctx, params["ref"], params["path"]) @@ -136,7 +136,7 @@ func gopherTreePath(tmpl *template.Template, haspath bool) sliderule.Handler { filetype := gopher.MenuType ext := path.Ext(params["path"]) - if ext != ".gophermap" && params["path"] != "gophermap" { + if ext != ".gph" && params["path"] != "gophermap" { mtype := mime.TypeByExtension(ext) if strings.HasPrefix(mtype, "text/") { filetype = gopher.TextFileType |