Documentation
¶
Overview ¶
Package static implements Credo's static file serving: sanitization of the router-decoded path, index and SPA fallbacks, directory listings, Range-aware file delivery, and status-aware Cache-Control. The root package owns the public StaticConfig/StaticRoute surface and the route registration; it converts its config into this package's Config and adapts the request Context to the ResponseWriter/http.Request pair the server consumes.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound reports a missing file or directory; the root package maps // it to its 404 error. ErrNotFound = errors.New("static: not found") // ErrBadRequest reports a malformed or unsafe path; the root package maps // it to its 400 error. ErrBadRequest = errors.New("static: bad request") )
Functions ¶
This section is empty.
Types ¶
type CacheContext ¶
CacheContext mirrors credo.StaticCacheContext field-for-field.
type Config ¶
type Config struct {
Index string
Browse bool
SPA bool
Download bool
CacheControl func(CacheContext) string
}
Config mirrors credo.StaticConfig. See that type for field semantics.
type FileServer ¶
type FileServer struct {
// contains filtered or unexported fields
}
FileServer serves one named file from an fs.FS.
func NewFileServer ¶
func NewFileServer(fsys fs.FS, name string, cfg Config) *FileServer
NewFileServer returns a FileServer for name inside fsys. The name is normalized once at construction.
func (*FileServer) Serve ¶
func (f *FileServer) Serve(w ResponseWriter, r *http.Request, requestPath string) error
Serve writes the file. Directories and missing files report ErrNotFound.
type ResponseWriter ¶
type ResponseWriter interface {
http.ResponseWriter
Committed() bool
}
ResponseWriter is the subset of the root Response the server writes to.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server serves files from an fs.FS under a route prefix.
func (*Server) Serve ¶
Serve resolves and writes filePath, the route-captured remainder ("" for the prefix itself). The router has already decoded it once, so it is a file path, not URL text: it is sanitized but never decoded again, and "%" is an ordinary character ("100%.txt"). requestPath is the client path before internal rewrites.