fs

package
v0.5.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2024 License: MIT Imports: 3 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddPrefixPathFS

type AddPrefixPathFS struct {
	// contains filtered or unexported fields
}

AddPrefixPathFS is a helper wrapper that will a prefix to each incoming filename that is to be opened. This is useful for embedFS which will keep their prefix. For example, mounting the embed fs go:embed static will retain the static/* prefix, while the static gin handler will strip it.

func NewAddPrefixPathFS

func NewAddPrefixPathFS(fs fs.FS, prefix string) AddPrefixPathFS

NewAddPrefixPathFS creates a new AddPrefixPathFS that will add the given prefix to each file that is opened..

func (AddPrefixPathFS) Open

func (s AddPrefixPathFS) Open(name string) (fs.File, error)

type EmbedFileSystem

type EmbedFileSystem struct {
	// contains filtered or unexported fields
}

EmbedFileSystem is a helper to make an embed FS work as a http.FS, which allows us to serve embed.FS using gin's `Static` middleware.

func NewEmbedFileSystem

func NewEmbedFileSystem(f fs.FS, stripPrefix string) *EmbedFileSystem

NewEmbedFileSystem will create a new EmbedFileSystem that will serve the given embed.FS under the given URL path. stripPrefix will be added to the beginning of all paths when looking up files in the embed.FS.

func (*EmbedFileSystem) Exists

func (e *EmbedFileSystem) Exists(prefix string, path string) bool

Exists will check if the given path exists in the embed.FS. The path will be prefixed with the stripPrefix that was given when creating the EmbedFileSystem, while prefix will be removed from the path.

func (*EmbedFileSystem) Open

func (e *EmbedFileSystem) Open(name string) (fs.File, error)

Open will open the file with the given name from the embed.FS. The name will be prefixed with the stripPrefix that was given when creating the EmbedFileSystem.

type StaticPath

type StaticPath struct {
	FS      fs.FS
	UrlPath string
}

StaticPath allows you to serve static files from a http.FileSystem under a given URL path UrlPath.

func NewStaticPath

func NewStaticPath(fs fs.FS, urlPath string) StaticPath

NewStaticPath creates a new StaticPath that will serve files from the given http.FileSystem.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL