Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIResponse ¶
type APIResponse[T any] struct { APIResponseMeta `json:"meta,omitempty"` Response T `json:"response,omitempty"` }
APIResponse is a generalized api response.
type APIResponseMeta ¶
APIResponseMeta is metadata for an api response.
type GracefulServer ¶
type GracefulServer struct { Server *http.Server Listener net.Listener ShutdownGracePeriod time.Duration OnStart []func() }
GracefulServer is a wrapper for an http server that implements the graceful interface.
func (*GracefulServer) RegisterOnStart ¶
func (gs *GracefulServer) RegisterOnStart(fn func())
RegisterOnStart registers an on-start handler.
type RewriteRule ¶
RewriteRule is a type that modifies a request.
type RewriteRuleFunc ¶
RewriteRuleFunc is a function that rewrites a url.
type StaticFileServer ¶
type StaticFileServer struct { SearchPaths []http.FileSystem RewriteRules []RewriteRule Headers http.Header }
StaticFileServer is a cache of static files. It can operate in cached mode, or with `CacheDisabled` set to `true` it will read from disk for each request. In cached mode, it automatically adds etags for files it caches.
func (*StaticFileServer) AddRegexPathRewrite ¶
func (sc *StaticFileServer) AddRegexPathRewrite(match string, rewriteAction func(string, ...string) string) error
AddRegexPathRewrite adds a re-write rule that modifies the url path.
Typically these kinds of re-write rules are used for vanity forms or removing a cache busting string from a given path.
func (*StaticFileServer) ResolveFile ¶
ResolveFile resolves a file from rewrite rules and search paths.
First the file path is modified according to the rewrite rules. Then each search path is checked for the resolved file path.
func (*StaticFileServer) ServeHTTP ¶
func (sc *StaticFileServer) ServeHTTP(rw http.ResponseWriter, req *http.Request)
ServeHTTP is the entrypoint for the static server.
It adds default headers if specified, and then serves the file from disk.