summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortjpcc <tjp@ctrl-c.club>2023-10-09 09:01:40 -0600
committertjpcc <tjp@ctrl-c.club>2023-10-09 09:01:40 -0600
commitac7849261967b0a5410c69669ff7809d5706133c (patch)
tree7dd75845fa34974fc9e0b5d631d84ded2f8363a0
parent68e2091437e178dc98987d463180c17bfe346b9a (diff)
gofmt, remove debugging
-rw-r--r--gemini.go43
-rw-r--r--gopher.go64
-rw-r--r--templates.go2
3 files changed, 56 insertions, 53 deletions
diff --git a/gemini.go b/gemini.go
index 91de5aa..878b2b8 100644
--- a/gemini.go
+++ b/gemini.go
@@ -22,32 +22,35 @@ const (
// GeminiRouter builds a router that will handle requests into a directory of git repositories.
//
// The routes it defines are:
-// / gemtext listing of the repositories in the directory
-// /:repository/ gemtext overview of the repository
-// /:repository/branches gemtext list of branches/heads
-// /:repository/tags gemtext listing of tags
-// /:repository/refs/:ref/ gemtext overview of a ref
-// /:repository/refs/:ref/tree/*path gemtext listing of directories, raw files
-// /:repository/diffstat/:fromref/:toref text/plain diffstat between two refs
-// /:repository/diff/:fromref/:toref text/x-diff between two refs
+//
+// / gemtext listing of the repositories in the directory
+// /:repository/ gemtext overview of the repository
+// /:repository/branches gemtext list of branches/heads
+// /:repository/tags gemtext listing of tags
+// /:repository/refs/:ref/ gemtext overview of a ref
+// /:repository/refs/:ref/tree/*path gemtext listing of directories, raw files
+// /:repository/diffstat/:fromref/:toref text/plain diffstat between two refs
+// /:repository/diff/:fromref/:toref text/x-diff between two refs
//
// 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 even be nil, but otherwise
// the template names used are:
-// repo_root.gmi gemtext at /
-// repo_home.gmi gemtext at /:repository/
-// branch_list.gmi gemtext at /:repository/branches
-// tag_list.gmi gemtext at /:repository/tags
-// ref.gmi gemtext at /:repository/refs/:ref/
-// tree.gmi gemtext for directories requested under /:repository/refs/:ref/tree/*path
-// (file paths return the raw files without any template involved)
-// diffstat.gmi.txt the plaintext diffstat at /:repository/diffstat/:fromref/:toref
-// diff.gmi.txt the text/x-diff at /:repository/diff/:fromref/:toref
+//
+// repo_root.gmi gemtext at /
+// repo_home.gmi gemtext at /:repository/
+// branch_list.gmi gemtext at /:repository/branches
+// tag_list.gmi gemtext at /:repository/tags
+// ref.gmi gemtext at /:repository/refs/:ref/
+// tree.gmi gemtext for directories requested under /:repository/refs/:ref/tree/*path
+// (file paths return the raw files without any template involved)
+// diffstat.gmi.txt the plaintext diffstat at /:repository/diffstat/:fromref/:toref
+// diff.gmi.txt the text/x-diff at /:repository/diff/:fromref/:toref
//
// Most of the templates above are rendered with an object with 3 fields:
-// Ctx: the context.Context from the request
-// Repo: a *syw.Repository object corresponding to <repodir>/:repository
-// Params: a map[string]string of the route parameters
+//
+// Ctx: the context.Context from the request
+// Repo: a *syw.Repository object corresponding to <repodir>/:repository
+// Params: a map[string]string of the route parameters
//
// The only exception is repo_root.gmi, which is rendered with a slice of the repo names instead.
func GeminiRouter(repodir string, overrides *template.Template) *sliderule.Router {
diff --git a/gopher.go b/gopher.go
index 3ad5ed2..d715641 100644
--- a/gopher.go
+++ b/gopher.go
@@ -3,11 +3,9 @@ package syw
import (
"bytes"
"context"
- "mime"
"os"
"path"
"path/filepath"
- "strings"
"text/template"
"tildegit.org/tjp/sliderule"
@@ -17,44 +15,48 @@ import (
// GopherRouter builds a router that will handle gopher requests in a directory of git repositories.
//
// The routes it defines are:
-// / .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
+//
+// / .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
//
// 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.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
+//
+// 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
-// Repo: a *syw.Repository corresponding to <repodir>/:repository
-// Params: the map[string]string of the route parameters
-// Host: the hostname of the running server
-// Port: the port number of the running server
-// Selector: the selector in the current request
+//
+// Ctx: the context.Context from the request
+// Repo: a *syw.Repository corresponding to <repodir>/:repository
+// Params: the map[string]string of the route parameters
+// Host: the hostname of the running server
+// Port: the port number of the running server
+// Selector: the selector in the current request
//
// 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
-// join: func(string, ...string) string - successively joins path segments
-// rawtext: func(selector, host, port, text string) string renders text lines as gopher info-message lines.
+//
+// combine: func(string, ...string) string - successively combines paths using url.URL.ResolveReference
+// join: func(string, ...string) string - successively joins path segments
+// rawtext: func(selector, host, port, text string) string renders text lines as gopher info-message lines.
func GopherRouter(repodir string, overrides *template.Template) *sliderule.Router {
tmpl, err := addTemplates(gopherTemplate, overrides)
if err != nil {
@@ -116,7 +118,7 @@ func gopherTreePath(tmpl *template.Template, haspath bool) sliderule.Handler {
t := "tree"
if haspath {
var err error
- t, err = repo.Type(ctx, params["ref"] + ":" + params["path"])
+ t, err = repo.Type(ctx, params["ref"]+":"+params["path"])
if err != nil {
return gopher.Error(err).Response()
}
diff --git a/templates.go b/templates.go
index c90cb09..f5f25af 100644
--- a/templates.go
+++ b/templates.go
@@ -2,7 +2,6 @@ package syw
import (
"embed"
- "fmt"
"net/url"
"strings"
"text/template"
@@ -39,7 +38,6 @@ func gopherCombine(base string, relative ...string) (string, error) {
if err != nil {
return "", err
}
- fmt.Println("combining", base, relative)
for _, rel := range relative {
ru, err := url.Parse(rel)