From 07c41d90a814df12223df607efb1922f51d97a61 Mon Sep 17 00:00:00 2001 From: toim Date: Sun, 29 Mar 2026 23:25:09 +0300 Subject: [PATCH] Add notes about leading slash in file related methods --- website/docs/guide/static-files.md | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/website/docs/guide/static-files.md b/website/docs/guide/static-files.md index 82780274..2c1f4ff3 100644 --- a/website/docs/guide/static-files.md +++ b/website/docs/guide/static-files.md @@ -4,10 +4,20 @@ slug: /static-files sidebar_position: 11 --- -# Static Files +# Serving Static Files Images, JavaScript, CSS, PDF, Fonts and so on... +## Default file system + +Echo uses `os.DirFS(".")` as default a file system which is set to current working directory. +To change the default file system, use `Echo#Filesystem` field. + +```go +e := echo.New() +e.Filesystem = os.DirFS("assets") +``` + ## Using Static Middleware [See ](/middleware/static.md) @@ -73,8 +83,16 @@ e.File("/", "public/index.html") *Usage 2* -Serving a favicon from `images/favicon.ico` +:::important + +Leading `/` in the file path is will not work with most of the fs.FS implementations. + +::: + +Serving a favicon from `/app/assets/favicon.ico` ```go -e.File("/favicon.ico", "images/favicon.ico") +e := echo.New() +e.Filesystem = os.DirFS("/") +e.File("/favicon.ico", "app/assets/favicon.ico") // <--- file path must not have a leading slash ```