diff options
author | Wim <wim@42.be> | 2022-09-05 21:00:54 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-05 21:00:54 +0200 |
commit | fda05f22629156cc2eae130b501ebced2261ab42 (patch) | |
tree | b9761fb5202ab476b11c1136a5bea69df0dd0f83 /vendor/github.com/labstack/echo/v4/context_fs.go | |
parent | 7abf1a5884bfba9ac19df26495924d86613874f3 (diff) | |
download | matterbridge-msglm-fda05f22629156cc2eae130b501ebced2261ab42.tar.gz matterbridge-msglm-fda05f22629156cc2eae130b501ebced2261ab42.tar.bz2 matterbridge-msglm-fda05f22629156cc2eae130b501ebced2261ab42.zip |
Update dependencies and fix whatsmeow API changes (#1887)
* Update dependencies
* Fix whatsmau API changes
Diffstat (limited to 'vendor/github.com/labstack/echo/v4/context_fs.go')
-rw-r--r-- | vendor/github.com/labstack/echo/v4/context_fs.go | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/vendor/github.com/labstack/echo/v4/context_fs.go b/vendor/github.com/labstack/echo/v4/context_fs.go index 11ee84bc..1038f892 100644 --- a/vendor/github.com/labstack/echo/v4/context_fs.go +++ b/vendor/github.com/labstack/echo/v4/context_fs.go @@ -1,33 +1,49 @@ -//go:build !go1.16 -// +build !go1.16 - package echo import ( + "errors" + "io" + "io/fs" "net/http" - "os" "path/filepath" ) -func (c *context) File(file string) (err error) { - f, err := os.Open(file) +func (c *context) File(file string) error { + return fsFile(c, file, c.echo.Filesystem) +} + +// FileFS serves file from given file system. +// +// When dealing with `embed.FS` use `fs := echo.MustSubFS(fs, "rootDirectory") to create sub fs which uses necessary +// prefix for directory path. This is necessary as `//go:embed assets/images` embeds files with paths +// including `assets/images` as their prefix. +func (c *context) FileFS(file string, filesystem fs.FS) error { + return fsFile(c, file, filesystem) +} + +func fsFile(c Context, file string, filesystem fs.FS) error { + f, err := filesystem.Open(file) if err != nil { - return NotFoundHandler(c) + return ErrNotFound } defer f.Close() fi, _ := f.Stat() if fi.IsDir() { - file = filepath.Join(file, indexPage) - f, err = os.Open(file) + file = filepath.ToSlash(filepath.Join(file, indexPage)) // ToSlash is necessary for Windows. fs.Open and os.Open are different in that aspect. + f, err = filesystem.Open(file) if err != nil { - return NotFoundHandler(c) + return ErrNotFound } defer f.Close() if fi, err = f.Stat(); err != nil { - return + return err } } - http.ServeContent(c.Response(), c.Request(), fi.Name(), fi.ModTime(), f) - return + ff, ok := f.(io.ReadSeeker) + if !ok { + return errors.New("file does not implement io.ReadSeeker") + } + http.ServeContent(c.Response(), c.Request(), fi.Name(), fi.ModTime(), ff) + return nil } |