MCPcopy
hub / github.com/pocketbase/pocketbase / FileFS

Method FileFS

tools/router/event.go:237–272  ·  view source on GitHub ↗

FileFS serves the specified filename from fsys. It is similar to [echo.FileFS] for consistency with earlier versions.

(fsys fs.FS, filename string)

Source from the content-addressed store, hash-verified

235//
236// It is similar to [echo.FileFS] for consistency with earlier versions.
237func (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).
275func (e *Event) NoContent(status int) error {

Callers 2

TestEventFileFSFunction · 0.95
StaticFunction · 0.80

Calls 3

ModTimeMethod · 0.80
OpenMethod · 0.65
CloseMethod · 0.65

Tested by 1

TestEventFileFSFunction · 0.76