FileFS serves the specified filename from fsys. It is similar to [echo.FileFS] for consistency with earlier versions.
(fsys fs.FS, filename string)
| 235 | // |
| 236 | // It is similar to [echo.FileFS] for consistency with earlier versions. |
| 237 | func (e *Event) FileFS(fsys fs.FS, filename string) error { |
| 238 | f, err := fsys.Open(filename) |
| 239 | if err != nil { |
| 240 | return ErrFileNotFound |
| 241 | } |
| 242 | defer f.Close() |
| 243 | |
| 244 | fi, err := f.Stat() |
| 245 | if err != nil { |
| 246 | return err |
| 247 | } |
| 248 | |
| 249 | // if it is a directory try to open its index.html file |
| 250 | if fi.IsDir() { |
| 251 | filename = filepath.ToSlash(filepath.Join(filename, IndexPage)) |
| 252 | f, err = fsys.Open(filename) |
| 253 | if err != nil { |
| 254 | return ErrFileNotFound |
| 255 | } |
| 256 | defer f.Close() |
| 257 | |
| 258 | fi, err = f.Stat() |
| 259 | if err != nil { |
| 260 | return err |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | ff, ok := f.(io.ReadSeeker) |
| 265 | if !ok { |
| 266 | return errors.New("[FileFS] file does not implement io.ReadSeeker") |
| 267 | } |
| 268 | |
| 269 | http.ServeContent(e.Response, e.Request, fi.Name(), fi.ModTime(), ff) |
| 270 | |
| 271 | return nil |
| 272 | } |
| 273 | |
| 274 | // NoContent writes a response with no body (ex. 204). |
| 275 | func (e *Event) NoContent(status int) error { |