diff options
author | tjpcc <tjp@ctrl-c.club> | 2023-05-01 07:56:25 -0600 |
---|---|---|
committer | tjpcc <tjp@ctrl-c.club> | 2023-05-01 07:56:25 -0600 |
commit | 9a2da81b11ad0064cca24ce7974827d032309369 (patch) | |
tree | 4313224dc089208423e78bffc3ec50833e35bcea /contrib/fs | |
parent | 21e2758145d100d74013060f7090d84679cae683 (diff) |
name change gus -> sliderule
Diffstat (limited to 'contrib/fs')
-rw-r--r-- | contrib/fs/dir.go | 8 | ||||
-rw-r--r-- | contrib/fs/dir_test.go | 14 | ||||
-rw-r--r-- | contrib/fs/file.go | 4 | ||||
-rw-r--r-- | contrib/fs/file_test.go | 10 | ||||
-rw-r--r-- | contrib/fs/gemini.go | 18 | ||||
-rw-r--r-- | contrib/fs/gopher.go | 18 | ||||
-rw-r--r-- | contrib/fs/spartan.go | 18 |
7 files changed, 45 insertions, 45 deletions
diff --git a/contrib/fs/dir.go b/contrib/fs/dir.go index 5659804..bb2d933 100644 --- a/contrib/fs/dir.go +++ b/contrib/fs/dir.go @@ -8,7 +8,7 @@ import ( "strings" "text/template" - "tildegit.org/tjp/gus" + sr "tildegit.org/tjp/sliderule" ) // ResolveDirectory opens the directory corresponding to a request path. @@ -16,7 +16,7 @@ import ( // The string is the full path to the directory. If the returned ReadDirFile // is not nil, it will be open and must be closed by the caller. func ResolveDirectory( - request *gus.Request, + request *sr.Request, fileSystem fs.FS, ) (string, fs.ReadDirFile, error) { path := strings.Trim(request.Path, "/") @@ -102,7 +102,7 @@ func RenderDirectoryListing( path string, dir fs.ReadDirFile, template *template.Template, - server gus.Server, + server sr.Server, ) (io.Reader, error) { buf := &bytes.Buffer{} @@ -118,7 +118,7 @@ func RenderDirectoryListing( return buf, nil } -func dirlistNamespace(path string, dirFile fs.ReadDirFile, server gus.Server) (map[string]any, error) { +func dirlistNamespace(path string, dirFile fs.ReadDirFile, server sr.Server) (map[string]any, error) { entries, err := dirFile.ReadDir(0) if err != nil { return nil, err diff --git a/contrib/fs/dir_test.go b/contrib/fs/dir_test.go index 9c6770d..6b6f60f 100644 --- a/contrib/fs/dir_test.go +++ b/contrib/fs/dir_test.go @@ -10,9 +10,9 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "tildegit.org/tjp/gus" - "tildegit.org/tjp/gus/contrib/fs" - "tildegit.org/tjp/gus/gemini" + sr "tildegit.org/tjp/sliderule" + "tildegit.org/tjp/sliderule/contrib/fs" + "tildegit.org/tjp/sliderule/gemini" ) func TestDirectoryDefault(t *testing.T) { @@ -20,7 +20,7 @@ func TestDirectoryDefault(t *testing.T) { tests := []struct { url string - status gus.Status + status sr.Status meta string body string }{ @@ -46,7 +46,7 @@ func TestDirectoryDefault(t *testing.T) { u, err := url.Parse(test.url) require.Nil(t, err) - request := &gus.Request{URL: u} + request := &sr.Request{URL: u} response := handler.Handle(context.Background(), request) if response == nil { @@ -73,7 +73,7 @@ func TestDirectoryListing(t *testing.T) { tests := []struct { url string - status gus.Status + status sr.Status meta string body string }{ @@ -107,7 +107,7 @@ func TestDirectoryListing(t *testing.T) { u, err := url.Parse(test.url) require.Nil(t, err) - request := &gus.Request{URL: u} + request := &sr.Request{URL: u} response := handler.Handle(context.Background(), request) if response == nil { diff --git a/contrib/fs/file.go b/contrib/fs/file.go index a1293af..591c1bd 100644 --- a/contrib/fs/file.go +++ b/contrib/fs/file.go @@ -5,7 +5,7 @@ import ( "mime" "strings" - "tildegit.org/tjp/gus" + sr "tildegit.org/tjp/sliderule" ) // ResolveFile finds a file from a filesystem based on a request path. @@ -13,7 +13,7 @@ import ( // It only returns a non-nil file if a file is found - not a directory. // If there is any other sort of filesystem access error, it will be // returned. -func ResolveFile(request *gus.Request, fileSystem fs.FS) (string, fs.File, error) { +func ResolveFile(request *sr.Request, fileSystem fs.FS) (string, fs.File, error) { filepath := strings.TrimPrefix(request.Path, "/") file, err := fileSystem.Open(filepath) if isNotFound(err) { diff --git a/contrib/fs/file_test.go b/contrib/fs/file_test.go index 3949b83..55e2a09 100644 --- a/contrib/fs/file_test.go +++ b/contrib/fs/file_test.go @@ -10,9 +10,9 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "tildegit.org/tjp/gus" - "tildegit.org/tjp/gus/contrib/fs" - "tildegit.org/tjp/gus/gemini" + sr "tildegit.org/tjp/sliderule" + "tildegit.org/tjp/sliderule/contrib/fs" + "tildegit.org/tjp/sliderule/gemini" ) func TestFileHandler(t *testing.T) { @@ -20,7 +20,7 @@ func TestFileHandler(t *testing.T) { tests := []struct { url string - status gus.Status + status sr.Status meta string body string }{ @@ -57,7 +57,7 @@ func TestFileHandler(t *testing.T) { u, err := url.Parse(test.url) require.Nil(t, err) - request := &gus.Request{URL: u} + request := &sr.Request{URL: u} response := handler.Handle(context.Background(), request) if response == nil { diff --git a/contrib/fs/gemini.go b/contrib/fs/gemini.go index 21ca32d..fbf8d08 100644 --- a/contrib/fs/gemini.go +++ b/contrib/fs/gemini.go @@ -6,15 +6,15 @@ import ( "strings" "text/template" - "tildegit.org/tjp/gus" - "tildegit.org/tjp/gus/gemini" + sr "tildegit.org/tjp/sliderule" + "tildegit.org/tjp/sliderule/gemini" ) // GeminiFileHandler builds a handler which serves up files from a file system. // // It only serves responses for paths which do not correspond to directories on disk. -func GeminiFileHandler(fileSystem fs.FS) gus.Handler { - return gus.HandlerFunc(func(ctx context.Context, request *gus.Request) *gus.Response { +func GeminiFileHandler(fileSystem fs.FS) sr.Handler { + return sr.HandlerFunc(func(ctx context.Context, request *sr.Request) *sr.Response { filepath, file, err := ResolveFile(request, fileSystem) if err != nil { return gemini.Failure(err) @@ -41,8 +41,8 @@ func GeminiFileHandler(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 any directory paths. -func GeminiDirectoryDefault(fileSystem fs.FS, filenames ...string) gus.Handler { - return gus.HandlerFunc(func(ctx context.Context, request *gus.Request) *gus.Response { +func GeminiDirectoryDefault(fileSystem fs.FS, filenames ...string) sr.Handler { + return sr.HandlerFunc(func(ctx context.Context, request *sr.Request) *sr.Response { dirpath, dir, response := handleDirGemini(request, fileSystem) if response != nil { return response @@ -77,8 +77,8 @@ func GeminiDirectoryDefault(fileSystem fs.FS, filenames ...string) gus.Handler { // // The template may be nil, in which case DefaultGeminiDirectoryList is used instead. The // template is then processed with RenderDirectoryListing. -func GeminiDirectoryListing(fileSystem fs.FS, template *template.Template) gus.Handler { - return gus.HandlerFunc(func(ctx context.Context, request *gus.Request) *gus.Response { +func GeminiDirectoryListing(fileSystem fs.FS, template *template.Template) sr.Handler { + return sr.HandlerFunc(func(ctx context.Context, request *sr.Request) *sr.Response { dirpath, dir, response := handleDirGemini(request, fileSystem) if response != nil { return response @@ -109,7 +109,7 @@ var DefaultGeminiDirectoryList = template.Must(template.New("gemini_dirlist").Pa => ../ `[1:])) -func handleDirGemini(request *gus.Request, fileSystem fs.FS) (string, fs.ReadDirFile, *gus.Response) { +func handleDirGemini(request *sr.Request, fileSystem fs.FS) (string, fs.ReadDirFile, *sr.Response) { path, dir, err := ResolveDirectory(request, fileSystem) if err != nil { return "", nil, gemini.Failure(err) diff --git a/contrib/fs/gopher.go b/contrib/fs/gopher.go index f63785c..e7e4ab9 100644 --- a/contrib/fs/gopher.go +++ b/contrib/fs/gopher.go @@ -8,15 +8,15 @@ import ( "strings" "text/template" - "tildegit.org/tjp/gus" - "tildegit.org/tjp/gus/gopher" + sr "tildegit.org/tjp/sliderule" + "tildegit.org/tjp/sliderule/gopher" ) // 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 GopherFileHandler(fileSystem fs.FS) gus.Handler { - return gus.HandlerFunc(func(ctx context.Context, request *gus.Request) *gus.Response { +func GopherFileHandler(fileSystem fs.FS) sr.Handler { + return sr.HandlerFunc(func(ctx context.Context, request *sr.Request) *sr.Response { filepath, file, err := ResolveFile(request, fileSystem) if err != nil { return gopher.Error(err).Response() @@ -39,8 +39,8 @@ 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 gus.HandlerFunc(func(ctx context.Context, request *gus.Request) *gus.Response { +func GopherDirectoryDefault(fileSystem fs.FS, filenames ...string) sr.Handler { + return sr.HandlerFunc(func(ctx context.Context, request *sr.Request) *sr.Response { dirpath, dir, err := ResolveDirectory(request, fileSystem) if err != nil { return gopher.Error(err).Response() @@ -71,8 +71,8 @@ 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 gus.HandlerFunc(func(ctx context.Context, request *gus.Request) *gus.Response { +func GopherDirectoryListing(fileSystem fs.FS, tpl *template.Template) sr.Handler { + return sr.HandlerFunc(func(ctx context.Context, request *sr.Request) *sr.Response { dirpath, dir, err := ResolveDirectory(request, fileSystem) if err != nil { return gopher.Error(err).Response() @@ -130,7 +130,7 @@ i {{ $hostname }} {{ $port }} ) // GuessGopherItemType attempts to find the best gopher item type for a file based on its name. -func GuessGopherItemType(filepath string) gus.Status { +func GuessGopherItemType(filepath string) sr.Status { ext := path.Ext(filepath) switch ext { case "txt", "gmi": diff --git a/contrib/fs/spartan.go b/contrib/fs/spartan.go index 550f549..70943ee 100644 --- a/contrib/fs/spartan.go +++ b/contrib/fs/spartan.go @@ -6,15 +6,15 @@ import ( "strings" "text/template" - "tildegit.org/tjp/gus" - "tildegit.org/tjp/gus/spartan" + sr "tildegit.org/tjp/sliderule" + "tildegit.org/tjp/sliderule/spartan" ) // SpartanFileHandler builds a handler which serves up files from a filesystem. // // It only serves responses for paths which do not correspond to directories on disk. -func SpartanFileHandler(fileSystem fs.FS) gus.Handler { - return gus.HandlerFunc(func(ctx context.Context, request *gus.Request) *gus.Response { +func SpartanFileHandler(fileSystem fs.FS) sr.Handler { + return sr.HandlerFunc(func(ctx context.Context, request *sr.Request) *sr.Response { filepath, file, err := ResolveFile(request, fileSystem) if err != nil { return spartan.ClientError(err) @@ -41,8 +41,8 @@ func SpartanFileHandler(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 any directory paths. -func SpartanDirectoryDefault(fileSystem fs.FS, filenames ...string) gus.Handler { - return gus.HandlerFunc(func(ctx context.Context, request *gus.Request) *gus.Response { +func SpartanDirectoryDefault(fileSystem fs.FS, filenames ...string) sr.Handler { + return sr.HandlerFunc(func(ctx context.Context, request *sr.Request) *sr.Response { dirpath, dir, response := handleDirSpartan(request, fileSystem) if response != nil { return response @@ -77,8 +77,8 @@ func SpartanDirectoryDefault(fileSystem fs.FS, filenames ...string) gus.Handler // // The tmeplate may be nil, in which cause DefaultSpartanDirectoryList is used instead. The // template is then processed with RenderDirectoryListing. -func SpartanDirectoryListing(filesystem fs.FS, template *template.Template) gus.Handler { - return gus.HandlerFunc(func(ctx context.Context, request *gus.Request) *gus.Response { +func SpartanDirectoryListing(filesystem fs.FS, template *template.Template) sr.Handler { + return sr.HandlerFunc(func(ctx context.Context, request *sr.Request) *sr.Response { dirpath, dir, response := handleDirSpartan(request, filesystem) if response != nil { return response @@ -103,7 +103,7 @@ func SpartanDirectoryListing(filesystem fs.FS, template *template.Template) gus. // DefaultSpartanDirectoryList is a template which renders a reasonable gemtext dir listing. var DefaultSpartanDirectoryList = DefaultGeminiDirectoryList -func handleDirSpartan(request *gus.Request, filesystem fs.FS) (string, fs.ReadDirFile, *gus.Response) { +func handleDirSpartan(request *sr.Request, filesystem fs.FS) (string, fs.ReadDirFile, *sr.Response) { path, dir, err := ResolveDirectory(request, filesystem) if err != nil { return "", nil, spartan.ServerError(err) |