lazyassets

package module
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2024 License: BSD-3-Clause Imports: 19 Imported by: 3

Documentation

Overview

Package lazyassets is a package that provides a simple way to manage assets in a web application.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = errors.New("not found")
)

Functions

This section is empty.

Types

type File

type File interface {
	Path() string
	Permalink() string

	Hash() string
	Integrity() string

	MimeType() string
}

type Route

type Route struct {
	Path      string
	Permalink string
	Loc       string
}

type Server

type Server struct {
	*Storage

	// PermalinkFiles is a function that returns true if the file should have a permalink
	// If nil, AllFiles is used
	PermalinkFiles TestFn

	// CSSTransformFiles is a function that returns true if the file css file should be transformed
	// If nil, AllFiles is used (meaning all css files)
	CSSTransformFiles TestFn

	// NextHandler is the next handler to call if the path is not found
	// If nil, 404 Not found is returned
	NextHandler http.Handler
}

func (*Server) Routes

func (m *Server) Routes() []Route

Routes returns all the routes that are available This is an expensive operation as it needs to hash all the files

func (*Server) ServeHTTP

func (m *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Storage

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

func (*Storage) AddFS

func (m *Storage) AddFS(fileSys fs.FS, prefix ...string) *Storage

func (*Storage) AddFile

func (m *Storage) AddFile(path string, content []byte) *Storage

func (*Storage) Find

func (m *Storage) Find(p string) (f File)

type TestFn

type TestFn func(f File) bool

func AllFiles

func AllFiles() TestFn

func OnlyAssets

func OnlyAssets() TestFn

OnlyAssets will have permalinks for images, css and js files

func OnlyDirectories

func OnlyDirectories(subfolders ...string) TestFn

func OnlyMimeTypes

func OnlyMimeTypes(mimes ...string) TestFn

func OnlySubDirectories

func OnlySubDirectories() TestFn

Jump to

Keyboard shortcuts

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