Documentation ¶
Overview ¶
Package static is a simple static web server with some simple useful features such as - Directory listing - Default index files - Single page mode (SPA) - Default CORS headers
Index ¶
- Constants
- Variables
- func FullVersion() string
- func IsExecutable(mode os.FileMode) bool
- type Middleware
- type Option
- type Router
- func (r *Router) DELETE(path string, handle httprouter.Handle)
- func (r *Router) File(path, name string)
- func (r *Router) GET(path string, handle httprouter.Handle)
- func (r *Router) Group(path string, m ...Middleware) *Router
- func (r *Router) HEAD(path string, handle httprouter.Handle)
- func (r *Router) Handle(method, path string, handle httprouter.Handle)
- func (r *Router) Handler(method, path string, handler http.Handler)
- func (r *Router) HandlerFunc(method, path string, handler http.HandlerFunc)
- func (r *Router) OPTIONS(path string, handle httprouter.Handle)
- func (r *Router) PATCH(path string, handle httprouter.Handle)
- func (r *Router) POST(path string, handle httprouter.Handle)
- func (r *Router) PUT(path string, handle httprouter.Handle)
- func (r *Router) ServeFiles(path string, root http.FileSystem)
- func (r *Router) ServeFilesWithCacheControl(path string, root fs.FS)
- func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (r *Router) Static(path, root string)
- func (r *Router) Use(m ...Middleware) *Router
- type Server
Constants ¶
const ( // DefaultBind is the default [<address>]:<port> to bind to DefaultBind = ":8000" // DefaultRoot is the default root directory to serve DefaultRoot = "." // DefaultCGI is the default for whether or not to enable execution of cgi scripts DefaultCGI = false // DefaultDir is the default for whether or not to enable directory listing DefaultDir = true // DefaultSPA is the default for whether or not to enable Single-Page-App (SPA) mode DefaultSPA = false )
Variables ¶
var ( // Version is the tagged release version in the form <major>.<minor>.<patch> // following semantic versioning and is overwritten by the build system. Version = defaultVersion // Commit is the commit sha of the build (normally from Git) and is overwritten // by the build system. Commit = defaultCommit // Build is the date and time of the build as an RFC3339 formatted string // and is overwritten by the build system. Build = defaultBuild )
var DefaultIndex = []string{"index.html", "index.html"}
DefaultIndex is the default set of index files to serve
Functions ¶
func IsExecutable ¶
IsExecutable returns true if the execution bits are set for the file mode
Types ¶
type Option ¶
Option is a function type that configures the server
func WithBind ¶
WithBind configures the server with a bind interface and port in the form of [<address>]:<port> For example: WithBind(":8000")
type Router ¶
type Router struct { httprouter.Router // contains filtered or unexported fields }
Router ...
func (*Router) DELETE ¶
func (r *Router) DELETE(path string, handle httprouter.Handle)
DELETE is a shortcut for Router.Handle("DELETE", path, handle)
func (*Router) GET ¶
func (r *Router) GET(path string, handle httprouter.Handle)
GET is a shortcut for Router.Handle("GET", path, handle)
func (*Router) Group ¶
func (r *Router) Group(path string, m ...Middleware) *Router
Group returns new *Router with given path and middlewares. It should be used for handles which have same path prefix or common middlewares.
func (*Router) HEAD ¶
func (r *Router) HEAD(path string, handle httprouter.Handle)
HEAD is a shortcut for Router.Handle("HEAD", path, handle)
func (*Router) Handle ¶
func (r *Router) Handle(method, path string, handle httprouter.Handle)
Handle registers a new request handle combined with middlewares.
func (*Router) HandlerFunc ¶
func (r *Router) HandlerFunc(method, path string, handler http.HandlerFunc)
HandlerFunc is an adapter for http.HandlerFunc.
func (*Router) OPTIONS ¶
func (r *Router) OPTIONS(path string, handle httprouter.Handle)
OPTIONS is a shortcut for Router.Handle("OPTIONS", path, handle)
func (*Router) PATCH ¶
func (r *Router) PATCH(path string, handle httprouter.Handle)
PATCH is a shortcut for Router.Handle("PATCH", path, handle)
func (*Router) POST ¶
func (r *Router) POST(path string, handle httprouter.Handle)
POST is a shortcut for Router.Handle("POST", path, handle)
func (*Router) PUT ¶
func (r *Router) PUT(path string, handle httprouter.Handle)
PUT is a shortcut for Router.Handle("PUT", path, handle)
func (*Router) ServeFiles ¶
func (r *Router) ServeFiles(path string, root http.FileSystem)
ServeFiles ...
func (*Router) ServeFilesWithCacheControl ¶
ServeFilesWithCacheControl ...
func (*Router) Use ¶
func (r *Router) Use(m ...Middleware) *Router
Use appends new middleware to current Router.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server constructs the static server, configures it and sets up initial routes
func (*Server) IndexHandler ¶
func (s *Server) IndexHandler() httprouter.Handle
IndexHandler handlers serving up resources and optionally performing directory listening (if enabled)