Documentation ¶
Index ¶
- Variables
- func GeminiDirectoryDefault(fsroot, urlroot string, filenames ...string) sr.Handler
- func GeminiDirectoryListing(fsroot, urlroot string, tmpl *template.Template) sr.Handler
- func GeminiFileHandler(fsroot, urlroot string) sr.Handler
- func GopherDirectoryDefault(fsroot, urlroot string, settings *gophermap.FileSystemSettings) sr.Handler
- func GopherDirectoryListing(fsroot, urlroot string, settings *gophermap.FileSystemSettings) sr.Handler
- func GopherFileHandler(fsroot, urlroot string, settings *gophermap.FileSystemSettings) sr.Handler
- func NexDirectoryDefault(fsroot, urlroot string, filenames ...string) sr.Handler
- func NexDirectoryListing(fsroot, urlroot string, tmpl *template.Template) sr.Handler
- func NexFileHandler(fsroot, urlroot string) sr.Handler
- func RenderDirectoryListing(path string, requestpath string, template *template.Template, server sr.Server) (io.Reader, error)
- func SpartanDirectoryDefault(fsroot, urlroot string, filenames ...string) sr.Handler
- func SpartanDirectoryListing(fsroot, urlroot string, tmpl *template.Template) sr.Handler
- func SpartanFileHandler(fsroot, urlroot string) sr.Handler
- func TitanUpload(fsroot, urlroot string, approver tlsauth.Approver) sr.Middleware
Constants ¶
This section is empty.
Variables ¶
var DefaultGeminiDirectoryList = template.Must(template.New("gemini_dirlist").Parse(`
# {{ .DirName }}
{{ range .Entries }}
=> {{ .Name }}{{ if .IsDir }}/{{ end -}}
{{ end }}
=> ../
`[1:]))
DefaultGeminiDirectoryList is a template which renders a reasonable gemtext dir list.
var DefaultNexDirectoryList = template.Must(template.New("nex_dirlist").Parse(`
{{ .DirName }} directory:
{{ range .Entries }}
=> ./{{ .Name }}{{ if .IsDir }}/{{ end -}}
{{ end }}
`[1:]))
var DefaultSpartanDirectoryList = DefaultGeminiDirectoryList
DefaultSpartanDirectoryList is a tmeplate which renders a reasonable gemtext dir listing.
Functions ¶
func GeminiDirectoryDefault ¶
GeminiDirectoryDefault serves up default files for directory path requests.
If any of the supported filenames are found, the contents of the file is returned as the gemini response.
It returns nil for any paths which don't correspond to a directory.
When it encounters a directory path which doesn't end in a trailing slash (/) it redirects to a URL with the trailing slash appended. This is necessary for relative links in the directory's contents to function properly.
func GeminiDirectoryListing ¶
GeminiDirectoryListing produces a listing of the contents of any requested directories.
It returns "51 Not Found" for any paths which don't correspond to a filesystem directory.
When it encounters a directory path which doesn't end in a trailing slash (/) it redirects to a URL with the trailing slash appended. This is necessary for relative links not the directory's contents to function properly.
The template may be nil, in which case DefaultGeminiDirectoryList is used instead. The template is then processed with RenderDirectoryListing.
func GeminiFileHandler ¶
GeminiFileHandler builds a handler which serves up files from the file system.
It only serves responses for paths which do not correspond to directories on disk.
func GopherDirectoryDefault ¶
func GopherDirectoryDefault(fsroot, urlroot string, settings *gophermap.FileSystemSettings) sr.Handler
GopherDirectoryDefault serves up default files for directory path requests.
If any of the supported filenames are found in the requested directory, the contents of that file is returned as the gopher response.
It returns nil for any paths which don't correspond to a directory.
func GopherDirectoryListing ¶
func GopherDirectoryListing(fsroot, urlroot string, settings *gophermap.FileSystemSettings) sr.Handler
GopherDirectoryListing produces a listing of the contents of any requested directories.
It returns nil for any paths which don't correspond to a filesystem directory.
func GopherFileHandler ¶
func GopherFileHandler(fsroot, urlroot string, settings *gophermap.FileSystemSettings) sr.Handler
GopherFileHandler builds a handler which serves up files from a file system.
It only serves responses for paths which correspond to files, not directories.
func NexDirectoryDefault ¶ added in v1.6.0
NexDirectoryDefault serves up default files for directory path requests.
If any of the supported filenames are found in the requested directory, the contents of that file is returned as the nex response.
It returns nil for any paths which don't correspond to a directory.
func NexDirectoryListing ¶ added in v1.6.0
NexDirectoryListing produces a listing of the contents of any requested directories.
It returns a nil response for any paths which don't correspond to a filesystem directory.
When it encounters a directory path which doesn't end in a trailing slash (/) it returns a nil response. Trailing slashes are necessary for relative links to work properly.
The template may be nil, in which case DefaultNexDirectoryList is used instead. The template is then processed with RenderDirectoryListing.
func NexFileHandler ¶ added in v1.6.0
NexFileHandler builds a handler which serves up files from a file system.
It only serves responses for paths which correspond to files, not directories.
func RenderDirectoryListing ¶
func RenderDirectoryListing( path string, requestpath string, template *template.Template, server sr.Server, ) (io.Reader, error)
RenderDirectoryListing provides an io.Reader with the output of a directory listing template.
The template is provided the following namespace:
- .FullPath: the complete path to the listed directory
- .DirName: the name of the directory itself
- .Entries: the []fs.DirEntry of the directory contents
- .Hostname: the hostname of the server hosting the file
- .Port: the port on which the server is listening
Each entry in .Entries has the following fields:
- .Name the string name of the item within the directory
- .IsDir is a boolean
- .Type is the FileMode bits
- .Info is a method returning (fs.FileInfo, error)
func SpartanDirectoryDefault ¶
SpartanDirectoryDefault serves up default files for directory path requests.
If any of the supported filenames are found, the contents of the file is returned as the spartan response.
It returns nil for any paths which don't correspond to a directory.
When it encounters a directory path which doesn't end in a trailing slash (/) it redirects to the URL with the slash appended. This is necessary for relative links in the directory's contents to function properly.
func SpartanDirectoryListing ¶
SpartanDirectoryListing produces a listing of the contents of any requested directories.
It returns a nil response for any paths which don't correspond to a filesystem directory.
When it encounters a directory path which doesn't end in a trailing slash (/) it redirects to a URL with the trailing slash appended. This is necessary for relative links not the directory's contents to function properly.
The template may be nil, in which case DefaultSpartanDirectoryList is used instead. The template is then processed with RenderDirectoryListing.
func SpartanFileHandler ¶
SpartanFileHandler builds a handler which serves up files from a root directory.
It only serves responses for paths which correspond to regular files or symlinks to them.
func TitanUpload ¶ added in v1.1.0
func TitanUpload(fsroot, urlroot string, approver tlsauth.Approver) sr.Middleware
TitanUpload decorates a handler to implement uploads via the titan protocol.
It is a middleware rather than a handler because after the upload is processed, the server is still responsible for generating a response.
Types ¶
This section is empty.