summaryrefslogtreecommitdiff
path: root/contrib/fs/gopher.go
diff options
context:
space:
mode:
authortjpcc <tjp@ctrl-c.club>2023-02-15 16:44:29 -0700
committertjpcc <tjp@ctrl-c.club>2023-02-15 16:44:29 -0700
commit46ad450327111b9d28b592658d75ef57da498298 (patch)
tree2b837bac9ae36d5a34dda06ba745850da216257d /contrib/fs/gopher.go
parentbc96af40db6104580c22086c8db7c8119a404257 (diff)
Switch Handler to an interface.
HandlerFunc is much better as a function returning a Handler, rather than a newtype for the function type itself. This way there is no confusion creating a type-inferenced variable with HandlerFunc(func(... and then using a HandlerFunc where a Handler is expected. Much better to only have one public type.
Diffstat (limited to 'contrib/fs/gopher.go')
-rw-r--r--contrib/fs/gopher.go12
1 files changed, 6 insertions, 6 deletions
diff --git a/contrib/fs/gopher.go b/contrib/fs/gopher.go
index 7b0d8bd..f63785c 100644
--- a/contrib/fs/gopher.go
+++ b/contrib/fs/gopher.go
@@ -16,7 +16,7 @@ import (
//
// It only serves responses for paths which correspond to files, not directories.
func GopherFileHandler(fileSystem fs.FS) gus.Handler {
- return func(ctx context.Context, request *gus.Request) *gus.Response {
+ return gus.HandlerFunc(func(ctx context.Context, request *gus.Request) *gus.Response {
filepath, file, err := ResolveFile(request, fileSystem)
if err != nil {
return gopher.Error(err).Response()
@@ -27,7 +27,7 @@ func GopherFileHandler(fileSystem fs.FS) gus.Handler {
}
return gopher.File(GuessGopherItemType(filepath), file)
- }
+ })
}
// GopherDirectoryDefault serves up default files for directory path requests.
@@ -40,7 +40,7 @@ func GopherFileHandler(fileSystem fs.FS) gus.Handler {
// It requires that files from the provided fs.FS implement fs.ReadDirFile. If
// they don't, it will produce nil responses for all directory paths.
func GopherDirectoryDefault(fileSystem fs.FS, filenames ...string) gus.Handler {
- return func(ctx context.Context, request *gus.Request) *gus.Response {
+ return gus.HandlerFunc(func(ctx context.Context, request *gus.Request) *gus.Response {
dirpath, dir, err := ResolveDirectory(request, fileSystem)
if err != nil {
return gopher.Error(err).Response()
@@ -59,7 +59,7 @@ func GopherDirectoryDefault(fileSystem fs.FS, filenames ...string) gus.Handler {
}
return gopher.File(gopher.MenuType, file)
- }
+ })
}
// GopherDirectoryListing produces a listing of the contents of any requested directories.
@@ -72,7 +72,7 @@ func GopherDirectoryDefault(fileSystem fs.FS, filenames ...string) gus.Handler {
// A template may be nil, in which case DefaultGopherDirectoryList is used instead. The
// template is then processed with RenderDirectoryListing.
func GopherDirectoryListing(fileSystem fs.FS, tpl *template.Template) gus.Handler {
- return func(ctx context.Context, request *gus.Request) *gus.Response {
+ return gus.HandlerFunc(func(ctx context.Context, request *gus.Request) *gus.Response {
dirpath, dir, err := ResolveDirectory(request, fileSystem)
if err != nil {
return gopher.Error(err).Response()
@@ -91,7 +91,7 @@ func GopherDirectoryListing(fileSystem fs.FS, tpl *template.Template) gus.Handle
}
return gopher.File(gopher.MenuType, body)
- }
+ })
}
// GopherTemplateFunctions is a map for templates providing useful functions for gophermaps.