{"modulePath":"github.com/bitechdev/ResolveSpec","version":"v1.3.14","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package staticweb\n\n## Types\n\n```go\ntype CachePolicy interface {\n\t// GetCacheTime returns the cache duration in seconds for the given path.\n\t// A value of 0 means no caching.\n\t// A negative value can be used to indicate browser should revalidate.\n\tGetCacheTime(path string) int\n\n\t// GetCacheHeaders returns additional cache-related HTTP headers for the given path.\n\t// Common headers include \"Cache-Control\", \"Expires\", \"ETag\", etc.\n\t// Returns nil if no additional headers are needed.\n\tGetCacheHeaders(path string) map[string]string\n}\n```\nCachePolicy defines how files should be cached by browsers and proxies. Implementations must be safe for concurrent use.\n\n```go\nfunc ExtensionCache(rules map[string]int, defaultTime int) CachePolicy\n```\nExtensionCache creates an extension-based cache policy. rules maps file extensions (with leading dot) to cache times in seconds. defaultTime is used for files that don't match any rule.\n\n```go\nfunc NoCache() CachePolicy\n```\nNoCache creates a cache policy that disables all caching.\n\n```go\nfunc SimpleCache(seconds int) CachePolicy\n```\nSimpleCache creates a simple cache policy with the given TTL in seconds.\n\n```go\ntype FallbackStrategy interface {\n\t// ShouldFallback determines if a fallback should be attempted for the given path.\n\t// Returns true if the request should be handled by fallback logic.\n\tShouldFallback(path string) bool\n\n\t// GetFallbackPath returns the path to serve instead of the originally requested path.\n\t// This is only called if ShouldFallback returns true.\n\tGetFallbackPath(path string) string\n}\n```\nFallbackStrategy handles requests for files that don't exist. This is commonly used for Single Page Applications (SPAs) that use client-side routing. Implementations must be safe for concurrent use.\n\n```go\nfunc DefaultExtensionFallback(fallbackPath string) FallbackStrategy\n```\nDefaultExtensionFallback creates an extension-based fallback with common web asset extensions.\n\n```go\nfunc ExtensionFallback(staticExtensions []string, fallbackPath string) FallbackStrategy\n```\nExtensionFallback creates an extension-based fallback strategy. staticExtensions is a list of file extensions that should NOT use fallback. fallbackPath is the file to serve when fallback is triggered.\n\n```go\nfunc HTMLFallback(indexFile string) FallbackStrategy\n```\nHTMLFallback creates a fallback strategy for SPAs that serves the given index file.\n\n```go\ntype FileSystemProvider interface {\n\t// Open opens the named file.\n\t// The name is always a slash-separated path relative to the filesystem root.\n\tOpen(name string) (fs.File, error)\n\n\t// Close releases any resources held by the provider.\n\t// After Close is called, the provider should not be used.\n\tClose() error\n\n\t// Type returns the provider type (e.g., \"local\", \"zip\", \"embed\", \"http\", \"s3\").\n\t// This is primarily for debugging and logging purposes.\n\tType() string\n}\n```\nFileSystemProvider abstracts the source of files (local, zip, embedded, future: http, s3) Implementations must be safe for concurrent use.\n\n```go\nfunc EmbedProvider(embedFS *embed.FS, zipFile string) (FileSystemProvider, error)\n```\nEmbedProvider creates a FileSystemProvider for an embedded filesystem. If zipFile is empty, the embedded FS is used directly. If zipFile is specified, it's treated as a path to a zip file within the embedded FS. The embedFS parameter can be any fs.FS, but is typically \\*embed.FS.\n\n```go\nfunc LocalProvider(path string) (FileSystemProvider, error)\n```\nLocalProvider creates a FileSystemProvider for a local directory.\n\n```go\nfunc WithStripPrefix(provider FileSystemProvider, prefix string) FileSystemProvider\n```\nWithStripPrefix is a helper function that sets the strip prefix on a provider if it implements PrefixStrippingProvider. Returns the provider for method chaining.\n\n```go\nfunc ZipProvider(zipPath string) (FileSystemProvider, error)\n```\nZipProvider creates a FileSystemProvider for a zip file.\n\n```go\ntype MIMETypeResolver interface {\n\t// GetMIMEType returns the MIME type for the given file path.\n\t// Returns empty string if the MIME type cannot be determined.\n\tGetMIMEType(path string) string\n\n\t// RegisterMIMEType registers a custom MIME type for the given file extension.\n\t// The extension should include the leading dot (e.g., \".webp\").\n\tRegisterMIMEType(extension, mimeType string)\n}\n```\nMIMETypeResolver determines the Content-Type for files. Implementations must be safe for concurrent use.\n\n```go\nfunc DefaultMIMEResolver() MIMETypeResolver\n```\nDefaultMIMEResolver creates a MIME resolver with common web file types.\n\n```go\ntype MountConfig struct {\n\t// URLPrefix is the URL path prefix where the filesystem should be mounted.\n\t// Must start with \"/\" (e.g., \"/static\", \"/\", \"/assets\").\n\t// Requests starting with this prefix will be handled by this mount point.\n\tURLPrefix string\n\n\t// Provider is the filesystem provider that supplies the files.\n\t// Required.\n\tProvider FileSystemProvider\n\n\t// CachePolicy determines how files should be cached.\n\t// If nil, the service's default cache policy is used.\n\tCachePolicy CachePolicy\n\n\t// MIMEResolver determines Content-Type headers for files.\n\t// If nil, the service's default MIME resolver is used.\n\tMIMEResolver MIMETypeResolver\n\n\t// FallbackStrategy handles requests for missing files.\n\t// If nil, no fallback is performed and 404 responses are returned.\n\tFallbackStrategy FallbackStrategy\n}\n```\nMountConfig configures a single mount point. A mount point connects a URL prefix to a filesystem provider with optional policies.\n\n```go\ntype PrefixStrippingProvider interface {\n\t// WithStripPrefix sets the prefix to strip from requested paths.\n\t// For example, WithStripPrefix(\"/dist\") will make files at \"/dist/assets\"\n\t// accessible via \"/assets\".\n\tWithStripPrefix(prefix string)\n\n\t// StripPrefix returns the configured strip prefix.\n\tStripPrefix() string\n}\n```\nPrefixStrippingProvider is an optional interface that providers can implement to support stripping path prefixes from requested paths. This is useful when files are stored in a subdirectory but should be accessible at the root level (e.g., files at \"/dist/assets\" accessible via \"/assets\").\n\n```go\ntype ReloadableProvider interface {\n\tFileSystemProvider\n\n\t// Reload refreshes the provider's content from the underlying source.\n\t// For zip files, this reopens the zip archive.\n\t// For local directories, this refreshes the filesystem view.\n\t// Returns an error if the reload fails.\n\tReload() error\n}\n```\nReloadableProvider is an optional interface that providers can implement to support reloading/refreshing their content. This is useful for development workflows where the underlying files may change.\n\n```go\ntype ServiceConfig struct {\n\t// DefaultCacheTime is the default cache duration in seconds.\n\t// Used when a mount point doesn't specify a custom CachePolicy.\n\t// Default: 172800 (48 hours)\n\tDefaultCacheTime int\n\n\t// DefaultMIMETypes is a map of file extensions to MIME types.\n\t// These are added to the default MIME resolver.\n\t// Extensions should include the leading dot (e.g., \".webp\").\n\tDefaultMIMETypes map[string]string\n}\n```\nServiceConfig configures the static file service.\n\n```go\nfunc DefaultServiceConfig() *ServiceConfig\n```\nDefaultServiceConfig returns a ServiceConfig with sensible defaults.\n\n```go\nfunc (c *ServiceConfig) Validate() error\n```\nValidate checks if the ServiceConfig is valid.\n\n```go\ntype StaticFileService interface {\n\t// Mount adds a new mount point with the given configuration.\n\t// Returns an error if the URLPrefix is already mounted or if the config is invalid.\n\tMount(config MountConfig) error\n\n\t// Unmount removes the mount point at the given URL prefix.\n\t// Returns an error if no mount point exists at that prefix.\n\t// Automatically calls Close() on the provider to release resources.\n\tUnmount(urlPrefix string) error\n\n\t// ListMounts returns a sorted list of all mounted URL prefixes.\n\tListMounts() []string\n\n\t// Reload reinitializes all filesystem providers.\n\t// This can be used to pick up changes in the underlying filesystems.\n\t// Not all providers may support reloading.\n\tReload() error\n\n\t// Close releases all resources held by the service and all mounted providers.\n\t// After Close is called, the service should not be used.\n\tClose() error\n\n\t// Handler returns an http.Handler that serves static files from all mount points.\n\t// The handler performs longest-prefix matching to find the appropriate mount point.\n\t// If no mount point matches, the handler returns without writing a response,\n\t// allowing other handlers (like API routes) to process the request.\n\tHandler() http.Handler\n}\n```\nStaticFileService manages multiple mount points and serves static files. The service is safe for concurrent use.\n\n```go\nfunc NewService(config *ServiceConfig) StaticFileService\n```\nNewService creates a new static file service with the given configuration. If config is nil, default configuration is used.\n\n","path":"github.com/bitechdev/ResolveSpec/pkg/server/staticweb","name":"staticweb","synopsis":"","isRedistributable":true}
