webassets

package
v0.0.0-...-e2c53ed Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: Apache-2.0 Imports: 8 Imported by: 1

README

Package cloudeng.io/webapp/webassets

import cloudeng.io/webapp/webassets

Functions

Func NewAssets
func NewAssets(prefix string, fsys fs.FS, opts ...AssetsOption) fs.FS

NewAssets returns an fs.FS that is configured to be optional reloaded from the local filesystem or to be served directly from the supplied fs.FS. The EnableReloading option is used to enable reloading. Prefix is prepended to all names passed to the supplied fs.FS, which is typically obtained via go:embed. See RelativeFS for more details.

Func RelativeFS
func RelativeFS(prefix string, fs fs.FS) fs.FS

RelativeFS wraps the supplied FS so that prefix is prepended to all of the paths fetched from it. This is generally useful when working with webservers where the FS containing files is created from 'assets/...' but the URL path to access them is at the root. So /index.html can be mapped to assets/index.html.

Func ServeFile
func ServeFile(wr io.Writer, fsys fs.FS, name string) (int, error)

ServeFile writes the specified file from the supplied fs.FS returning to the supplied writer, returning an appropriate http status code.

Types

Type AssetsFlags
type AssetsFlags struct {
	ReloadEnable    bool   `subcmd:"reload-enable,false,'if set, newer local filesystem versions of embedded asset files will be used'"`
	ReloadNew       bool   `subcmd:"reload-new-files,true,'if set, files that only exist on the local filesystem may be used'"`
	ReloadRoot      string `subcmd:"reload-root,$PWD,'the filesystem location that contains assets to be used in preference to embedded ones. This is generally set to the directory that the application was built in to allow for updated versions of the original embedded assets to be used. It defaults to the current directory. For external/production use this will generally refer to a different directory.'"`
	ReloadLogging   bool   `subcmd:"reload-logging,false,set to enable logging"`
	ReloadDebugging bool   `subcmd:"reload-debugging,false,set to enable debug logging"`
}

AssetsFlags represents the flags used to control loading of assets from the local filesystem to override those original embedded in the application binary.

Type AssetsOption
type AssetsOption func(a *assets)

AssetsOption represents an option to NewAssets.

Functions
func EnableDebugging() AssetsOption

EnableDebugging enables debug output.

func EnableLogging() AssetsOption

EnableLogging enables logging using a built in logging function.

func EnableReloading(location string, after time.Time, loadNew bool) AssetsOption

EnableReloading enables reloading of assets from the specified location if they have changed since 'after'; loadNew controls whether new files, ie. those that exist only in location, are loaded as opposed. See cloudeng.io/io/reloadfs.

func OptionsFromFlags(rf *AssetsFlags) []AssetsOption

OptionsFromFlags parses AssetsFlags to determine the options to be passed to NewAssets()

func UseLogger(logger func(action reloadfs.Action, name, path string, err error)) AssetsOption

UseLogger enables logging using the supplied logging function.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAssets

func NewAssets(prefix string, fsys fs.FS, opts ...AssetsOption) fs.FS

NewAssets returns an fs.FS that is configured to be optional reloaded from the local filesystem or to be served directly from the supplied fs.FS. The EnableReloading option is used to enable reloading. Prefix is prepended to all names passed to the supplied fs.FS, which is typically obtained via go:embed. See RelativeFS for more details.

func RelativeFS

func RelativeFS(prefix string, fs fs.FS) fs.FS

RelativeFS wraps the supplied FS so that prefix is prepended to all of the paths fetched from it. This is generally useful when working with webservers where the FS containing files is created from 'assets/...' but the URL path to access them is at the root. So /index.html can be mapped to assets/index.html.

func ServeFile

func ServeFile(wr io.Writer, fsys fs.FS, name string) (int, error)

ServeFile writes the specified file from the supplied fs.FS returning to the supplied writer, returning an appropriate http status code.

Types

type AssetsFlags

type AssetsFlags struct {
	ReloadEnable    bool   `subcmd:"reload-enable,false,'if set, newer local filesystem versions of embedded asset files will be used'"`
	ReloadNew       bool   `subcmd:"reload-new-files,true,'if set, files that only exist on the local filesystem may be used'"`
	ReloadRoot      string `` /* 380-byte string literal not displayed */
	ReloadLogging   bool   `subcmd:"reload-logging,false,set to enable logging"`
	ReloadDebugging bool   `subcmd:"reload-debugging,false,set to enable debug logging"`
}

AssetsFlags represents the flags used to control loading of assets from the local filesystem to override those original embedded in the application binary.

type AssetsOption

type AssetsOption func(a *assets)

AssetsOption represents an option to NewAssets.

func EnableDebugging

func EnableDebugging() AssetsOption

EnableDebugging enables debug output.

func EnableLogging

func EnableLogging() AssetsOption

EnableLogging enables logging using a built in logging function.

func EnableReloading

func EnableReloading(location string, after time.Time, loadNew bool) AssetsOption

EnableReloading enables reloading of assets from the specified location if they have changed since 'after'; loadNew controls whether new files, ie. those that exist only in location, are loaded as opposed. See cloudeng.io/io/reloadfs.

func OptionsFromFlags

func OptionsFromFlags(rf *AssetsFlags) []AssetsOption

OptionsFromFlags parses AssetsFlags to determine the options to be passed to NewAssets()

func UseLogger

func UseLogger(logger func(action reloadfs.Action, name, path string, err error)) AssetsOption

UseLogger enables logging using the supplied logging function.

Jump to

Keyboard shortcuts

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