Documentation
¶
Overview ¶
package assettube fingerprints and servers your assets processed by webpack/gulp/other-tools from your Go application.
AssetTube copys your asset files into a subdirectory named `assettube` and fingerprints them, in runtime. Every time the server is restarted, it will remove previously generated files and generates new files.
Index ¶
- Variables
- func Add(root string) error
- func AssetPath(p string) string
- func Integrity(p string) string
- func JSCSSOnly(path string, info os.FileInfo) bool
- func Link(p string, attrs ...string) template.HTML
- func Script(p string, attrs ...string) template.HTML
- func ServeHTTP(w http.ResponseWriter, r *http.Request)
- func SetConfig(cfg Config) error
- type Config
- type HashType
- type Manager
- func (m *Manager) Add(root string) error
- func (m *Manager) AssetPath(p string) string
- func (m *Manager) Integrity(p string) string
- func (m *Manager) Link(p string, attrs ...string) template.HTML
- func (m *Manager) Script(p string, attrs ...string) template.HTML
- func (m *Manager) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (m *Manager) SetConfig(cfg Config) error
Constants ¶
This section is empty.
Variables ¶
var DefaultManager, _ = NewManager(Config{})
Functions ¶
func Add ¶
Add includes path in Manager serving scope. It also copies and fingerprints assets into a subdirectory named "assettube". Every time it's called it removes the subdirectory and create a new one, then copy all the matched files into the new directory.
func AssetPath ¶
AssetPath returns the fingerprinted filename, with Hostname and URLPrefix if configured. It's mostly used as a template function for package html/template or text/template.
func Integrity ¶
Integrity returns the SRI hash of corresponding file. You could specify which digest hash to use by Config.HashType. https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity
Types ¶
type Config ¶
type Config struct { Fingerprint bool // Fingerprint option. False by default, so you could only enable it for production server. URLPrefix string // URLPrefix prepends url in the fingerprinted filename returned from Manager. Hostname string // Hostname specifies CDN hostname. Empty by default. // Matcher decides what files AssetTube Manager should fingerprint and serve. // The default matcher only handle JS and CSS files (i.e.: *.js, *.css). Matcher func(path string, info os.FileInfo) bool // Enable SubresourceIntegrity support and specify digest hash method by HashType. // Note: SubresourceIntegrity only works when Fingerprint is enabled. SubresourceIntegrity bool HashType HashType // Default HashType is HTSHA384(SHA-384). Logger io.Writer }
type HashType ¶
type HashType int
HashType represents the hash function used in Subresource Integrity.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager processes and serves the file content.
func NewManager ¶
NewManager returns an AssetTube Manager.
func NewManagerManifest ¶
func (*Manager) Add ¶
Add includes path in Manager serving scope. It also copies and fingerprints assets into a subdirectory named "assettube". Every time it's called it removes the subdirectory and create a new one, then copy all the matched files into the new directory.
func (*Manager) AssetPath ¶
AssetPath returns the fingerprinted filename, with Hostname and URLPrefix if configured. It's mostly used as a template function for package html/template or text/template.
func (*Manager) Integrity ¶
Integrity returns the SRI hash of corresponding file. You could specify which digest hash to use by Config.HashType. https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity