fs

package
v1.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2023 License: Unlicense Imports: 20 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
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.

View Source
var DefaultNexDirectoryList = template.Must(template.New("nex_dirlist").Parse(`
{{ .DirName }} directory:
{{ range .Entries }}
=> ./{{ .Name }}{{ if .IsDir }}/{{ end -}}
{{ end }}
`[1:]))
View Source
var DefaultSpartanDirectoryList = DefaultGeminiDirectoryList

DefaultSpartanDirectoryList is a tmeplate which renders a reasonable gemtext dir listing.

Functions

func GeminiDirectoryDefault

func GeminiDirectoryDefault(fsroot, urlroot string, filenames ...string) sr.Handler

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

func GeminiDirectoryListing(fsroot, urlroot string, tmpl *template.Template) sr.Handler

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

func GeminiFileHandler(fsroot, urlroot string) sr.Handler

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

func NexDirectoryDefault(fsroot, urlroot string, filenames ...string) sr.Handler

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

func NexDirectoryListing(fsroot, urlroot string, tmpl *template.Template) sr.Handler

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

func NexFileHandler(fsroot, urlroot string) sr.Handler

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

func SpartanDirectoryDefault(fsroot, urlroot string, filenames ...string) sr.Handler

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

func SpartanDirectoryListing(fsroot, urlroot string, tmpl *template.Template) sr.Handler

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

func SpartanFileHandler(fsroot, urlroot string) sr.Handler

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL