2024-04-28 13:08:41 +02:00
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
// SPDX-FileCopyrightText: © 2015 LabStack LLC and Echo contributors
|
|
|
|
|
2022-08-18 01:16:43 +02:00
|
|
|
package echo
|
|
|
|
|
2022-11-02 17:50:56 +01:00
|
|
|
import (
|
|
|
|
"io/fs"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
2022-08-18 01:16:43 +02:00
|
|
|
// Static implements `Echo#Static()` for sub-routes within the Group.
|
2022-11-02 17:50:56 +01:00
|
|
|
func (g *Group) Static(pathPrefix, fsRoot string) {
|
|
|
|
subFs := MustSubFS(g.echo.Filesystem, fsRoot)
|
|
|
|
g.StaticFS(pathPrefix, subFs)
|
|
|
|
}
|
|
|
|
|
|
|
|
// StaticFS implements `Echo#StaticFS()` for sub-routes within the Group.
|
|
|
|
//
|
|
|
|
// 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 (g *Group) StaticFS(pathPrefix string, filesystem fs.FS) {
|
|
|
|
g.Add(
|
|
|
|
http.MethodGet,
|
|
|
|
pathPrefix+"*",
|
|
|
|
StaticDirectoryHandler(filesystem, false),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// FileFS implements `Echo#FileFS()` for sub-routes within the Group.
|
|
|
|
func (g *Group) FileFS(path, file string, filesystem fs.FS, m ...MiddlewareFunc) *Route {
|
|
|
|
return g.GET(path, StaticFileHandler(file, filesystem), m...)
|
2022-08-18 01:16:43 +02:00
|
|
|
}
|