diff --git a/net/http/fs/fs.go b/net/http/fs/fs.go deleted file mode 100644 index f2ce235..0000000 --- a/net/http/fs/fs.go +++ /dev/null @@ -1,47 +0,0 @@ -package fs - -import ( - "fmt" - "io/fs" - "os" -) - -var _ fs.FS = (FS{}) - -// An FS provides access to a hierarchical file system. -type FS struct { - fsys fs.FS -} - -// Must panics if there is an error returning the subtree -func Must(fsys fs.FS, name string) FS { - f, err := Sub(fsys, name) - if err != nil { - panic(err) - } - return f -} - -// Sub returns an FS corresponding to the subtree rooted at fsys's dir. -func Sub(fsys fs.FS, name string) (FS, error) { - f, err := fs.Sub(fsys, name) - if err != nil { - return FS{}, fmt.Errorf("sub: %w", err) - } - return FS{fsys: f}, nil -} - -// Open tries to open the file with the supplied name. If not found retires with `.html` extension -func (fsys FS) Open(name string) (fs.File, error) { - f, err := fsys.fsys.Open(name) - if os.IsNotExist(err) { - if f, err := fsys.fsys.Open(name + ".html"); err == nil { - return f, nil - } - } - return f, err -} - -func NewFS(fsys fs.FS) *FS { - return &FS{fsys: fsys} -} diff --git a/net/http/fs/fs_test.go b/net/http/fs/fs_test.go deleted file mode 100644 index e2d805b..0000000 --- a/net/http/fs/fs_test.go +++ /dev/null @@ -1,26 +0,0 @@ -package fs_test - -import ( - "embed" - "testing" - - "go.adoublef.dev/is" - "go.adoublef.dev/sdk/net/http/fs" -) - -//go:embed all:testdata -var embedFS embed.FS - -// var fsys = fs.Must(embedFS, "testdata") - -func TestFS(t *testing.T) { - t.Run("sub-root of file system", func(t *testing.T) { - is := is.New(t) - - fs, err := fs.Sub(embedFS, "testdata") - is.NoErr(err) // subtree of embedded file system - - _, err = fs.Open("a") - is.NoErr(err) // open file `a.html` using the filename - }) -} diff --git a/net/http/fs/testdata/a.html b/net/http/fs/testdata/a.html deleted file mode 100644 index e69de29..0000000