Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConfigurableMIMEResolver ¶
type ConfigurableMIMEResolver struct {
// contains filtered or unexported fields
}
ConfigurableMIMEResolver implements a MIME type resolver with user-defined mappings only. It does not use any default mappings.
func NewConfigurableMIMEResolver ¶
func NewConfigurableMIMEResolver(types map[string]string) *ConfigurableMIMEResolver
NewConfigurableMIMEResolver creates a new ConfigurableMIMEResolver with the given mappings.
func (*ConfigurableMIMEResolver) GetMIMEType ¶
func (r *ConfigurableMIMEResolver) GetMIMEType(filePath string) string
GetMIMEType returns the MIME type for the given file path.
func (*ConfigurableMIMEResolver) RegisterMIMEType ¶
func (r *ConfigurableMIMEResolver) RegisterMIMEType(extension, mimeType string)
RegisterMIMEType registers a MIME type for the given file extension.
type DefaultMIMEResolver ¶
type DefaultMIMEResolver struct {
// contains filtered or unexported fields
}
DefaultMIMEResolver implements a MIME type resolver using Go's standard mime package and a set of common web file type mappings.
func NewDefaultMIMEResolver ¶
func NewDefaultMIMEResolver() *DefaultMIMEResolver
NewDefaultMIMEResolver creates a new DefaultMIMEResolver with common web MIME types.
func (*DefaultMIMEResolver) GetMIMEType ¶
func (r *DefaultMIMEResolver) GetMIMEType(filePath string) string
GetMIMEType returns the MIME type for the given file path. It first checks custom registered types, then falls back to Go's mime.TypeByExtension.
func (*DefaultMIMEResolver) RegisterMIMEType ¶
func (r *DefaultMIMEResolver) RegisterMIMEType(extension, mimeType string)
RegisterMIMEType registers a custom MIME type for the given file extension.
type ExtensionBasedCachePolicy ¶
type ExtensionBasedCachePolicy struct {
// contains filtered or unexported fields
}
ExtensionBasedCachePolicy implements a cache policy that varies by file extension.
func NewExtensionBasedCachePolicy ¶
func NewExtensionBasedCachePolicy(rules map[string]int, defaultTime int) *ExtensionBasedCachePolicy
NewExtensionBasedCachePolicy creates a new ExtensionBasedCachePolicy. rules maps file extensions (with leading dot, e.g., ".js") to cache times in seconds. defaultTime is used for files that don't match any rule.
func (*ExtensionBasedCachePolicy) GetCacheHeaders ¶
func (p *ExtensionBasedCachePolicy) GetCacheHeaders(filePath string) map[string]string
GetCacheHeaders returns cache headers based on the file extension.
func (*ExtensionBasedCachePolicy) GetCacheTime ¶
func (p *ExtensionBasedCachePolicy) GetCacheTime(filePath string) int
GetCacheTime returns the cache duration based on the file extension.
type ExtensionBasedFallback ¶
type ExtensionBasedFallback struct {
// contains filtered or unexported fields
}
ExtensionBasedFallback implements a fallback strategy that skips fallback for known static file extensions. This is the behavior from the original StaticHTMLFallbackHandler.
func NewDefaultExtensionBasedFallback ¶
func NewDefaultExtensionBasedFallback(fallbackPath string) *ExtensionBasedFallback
NewDefaultExtensionBasedFallback creates an ExtensionBasedFallback with common web asset extensions. This matches the behavior of the original StaticHTMLFallbackHandler.
func NewExtensionBasedFallback ¶
func NewExtensionBasedFallback(staticExtensions []string, fallbackPath string) *ExtensionBasedFallback
NewExtensionBasedFallback creates a new ExtensionBasedFallback strategy. staticExtensions is a list of file extensions (with leading dot) that should NOT use fallback. fallbackPath is the file to serve when fallback is triggered.
func (*ExtensionBasedFallback) GetFallbackPath ¶
func (f *ExtensionBasedFallback) GetFallbackPath(filePath string) string
GetFallbackPath returns the configured fallback path.
func (*ExtensionBasedFallback) ShouldFallback ¶
func (f *ExtensionBasedFallback) ShouldFallback(filePath string) bool
ShouldFallback returns true if the file path doesn't have a static asset extension.
type HTMLExtensionFallback ¶
type HTMLExtensionFallback struct {
// contains filtered or unexported fields
}
HTMLExtensionFallback implements a fallback strategy that appends .html to paths. This tries to serve {path}.html for missing files.
func NewHTMLExtensionFallback ¶
func NewHTMLExtensionFallback(staticExtensions []string) *HTMLExtensionFallback
NewHTMLExtensionFallback creates a new HTMLExtensionFallback strategy.
func (*HTMLExtensionFallback) GetFallbackPath ¶
func (f *HTMLExtensionFallback) GetFallbackPath(filePath string) string
GetFallbackPath returns the path with .html appended.
func (*HTMLExtensionFallback) ShouldFallback ¶
func (f *HTMLExtensionFallback) ShouldFallback(filePath string) bool
ShouldFallback returns true if the path doesn't have a static extension or .html.
type HTMLFallbackStrategy ¶
type HTMLFallbackStrategy struct {
// contains filtered or unexported fields
}
HTMLFallbackStrategy implements a fallback strategy for Single Page Applications (SPAs). It serves a specified HTML file (typically index.html) for non-file requests.
func NewHTMLFallbackStrategy ¶
func NewHTMLFallbackStrategy(indexFile string) *HTMLFallbackStrategy
NewHTMLFallbackStrategy creates a new HTMLFallbackStrategy. indexFile is the path to the HTML file to serve (e.g., "index.html", "/index.html").
func (*HTMLFallbackStrategy) GetFallbackPath ¶
func (f *HTMLFallbackStrategy) GetFallbackPath(filePath string) string
GetFallbackPath returns the index file path.
func (*HTMLFallbackStrategy) ShouldFallback ¶
func (f *HTMLFallbackStrategy) ShouldFallback(filePath string) bool
ShouldFallback returns true for requests that don't look like static assets.
type NoCachePolicy ¶
type NoCachePolicy struct{}
NoCachePolicy implements a cache policy that disables all caching.
func NewNoCachePolicy ¶
func NewNoCachePolicy() *NoCachePolicy
NewNoCachePolicy creates a new NoCachePolicy.
func (*NoCachePolicy) GetCacheHeaders ¶
func (p *NoCachePolicy) GetCacheHeaders(filePath string) map[string]string
GetCacheHeaders returns headers that disable caching.
func (*NoCachePolicy) GetCacheTime ¶
func (p *NoCachePolicy) GetCacheTime(filePath string) int
GetCacheTime always returns 0 (no caching).
type NoFallback ¶
type NoFallback struct{}
NoFallback implements a fallback strategy that never falls back. All requests for missing files will result in 404 responses.
func NewNoFallback ¶
func NewNoFallback() *NoFallback
NewNoFallback creates a new NoFallback strategy.
func (*NoFallback) GetFallbackPath ¶
func (f *NoFallback) GetFallbackPath(filePath string) string
GetFallbackPath returns an empty string (never called since ShouldFallback returns false).
func (*NoFallback) ShouldFallback ¶
func (f *NoFallback) ShouldFallback(filePath string) bool
ShouldFallback always returns false.
type SimpleCachePolicy ¶
type SimpleCachePolicy struct {
// contains filtered or unexported fields
}
SimpleCachePolicy implements a basic cache policy with a single TTL for all files.
func NewSimpleCachePolicy ¶
func NewSimpleCachePolicy(cacheTimeSeconds int) *SimpleCachePolicy
NewSimpleCachePolicy creates a new SimpleCachePolicy with the given cache time in seconds.
func (*SimpleCachePolicy) GetCacheHeaders ¶
func (p *SimpleCachePolicy) GetCacheHeaders(filePath string) map[string]string
GetCacheHeaders returns the Cache-Control header for the given file.
func (*SimpleCachePolicy) GetCacheTime ¶
func (p *SimpleCachePolicy) GetCacheTime(filePath string) int
GetCacheTime returns the cache duration for any file.