Documentation ¶
Index ¶
- func AccessLoggingMiddleware(logger logs.Logger) func(http.Handler) http.Handler
- func CatchAll(_ *http.Request) bool
- func DisallowedRobotsTXT(routes []string) string
- func FileServer(dirPath, httpPrefix string) http.Handler
- func IPAddressFromRequest(r *http.Request, useXForwardedFor bool) net.IP
- func MatchMethodConnect(r *http.Request) bool
- func MatchMethodDelete(r *http.Request) bool
- func MatchMethodGet(r *http.Request) bool
- func MatchMethodHead(r *http.Request) bool
- func MatchMethodOptions(r *http.Request) bool
- func MatchMethodPatch(r *http.Request) bool
- func MatchMethodPost(r *http.Request) bool
- func MatchMethodPut(r *http.Request) bool
- func MatchMethodTrace(r *http.Request) bool
- func MustParseHTMLTemplate(commonTmpls []string, path string) *template.Template
- func MustParseHTMLTemplateFS(fsys fs.FS, commonTmpls []string, path string) *template.Template
- func NewServerWithDefaults(h http.Handler, port int) *http.Server
- func PanicRecoveryMiddleware(onPanic PanicHandler) func(h http.Handler) http.Handler
- func PermanentRedirectHandler(toURL string) http.HandlerFunc
- func ReadAndServeFile(path string) http.HandlerFunc
- func RenderHTMLTemplate(w http.ResponseWriter, statusCode int, t *template.Template, tname string, ...)
- func RunServer(s *http.Server, onShutown func() error) error
- func ServeMonochromeFaviconPNG(c color.Color) http.HandlerFunc
- func ServeRaw(v []byte) http.HandlerFunc
- func ServeRobotsTXT(disallowedRoutes ...string) http.HandlerFunc
- func ServeSitemapXML(host string, routes ...string) http.HandlerFunc
- func SitemapXML(host string, routes ...string) string
- func VisitorHash(r *http.Request, checkXForwardedFor bool) string
- func Wrap(h http.Handler, middleware func(http.Handler) http.Handler) http.Handler
- type JSONLDWebsiteSchema
- type PanicHandler
- type RequestMatcher
- func MatchDomainName(s string) RequestMatcher
- func MatchHeader(k, v string) RequestMatcher
- func MatchHostname(s string) RequestMatcher
- func MatchMethod(methods ...string) RequestMatcher
- func MatchPath(path string) RequestMatcher
- func MatchPathPrefix(prefix string) RequestMatcher
- func MatchSubdomain(s string) RequestMatcher
- type ResponseStatusRecorder
- type Route
- type Routes
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AccessLoggingMiddleware ¶
Access logging middleware logs incoming HTTP requests
func CatchAll ¶
Defined for readability purposes, to make it explicit that the handlers intents to catch all requests. Used for handling 404s. Equivalent to not using any RequestMatcher in routes.Handle, as this will match any request.
func DisallowedRobotsTXT ¶
Generate robots.txt with disallowed routes
func FileServer ¶
func IPAddressFromRequest ¶
func MatchMethodConnect ¶ added in v0.0.6
func MatchMethodDelete ¶ added in v0.0.6
func MatchMethodGet ¶ added in v0.0.1
Utility request method matchers defined for convenience and conciseness.
func MatchMethodHead ¶ added in v0.0.6
func MatchMethodOptions ¶ added in v0.0.6
func MatchMethodPatch ¶ added in v0.0.6
func MatchMethodPost ¶ added in v0.0.1
func MatchMethodPut ¶ added in v0.0.6
func MatchMethodTrace ¶ added in v0.0.6
func MustParseHTMLTemplate ¶
func MustParseHTMLTemplateFS ¶ added in v0.0.3
func PanicRecoveryMiddleware ¶
func PanicRecoveryMiddleware(onPanic PanicHandler) func(h http.Handler) http.Handler
Panic recovery middleware logs the recovered error and executes the onPanic callback function.
func PermanentRedirectHandler ¶
func PermanentRedirectHandler(toURL string) http.HandlerFunc
func ReadAndServeFile ¶
func ReadAndServeFile(path string) http.HandlerFunc
func RenderHTMLTemplate ¶
func RenderHTMLTemplate( w http.ResponseWriter, statusCode int, t *template.Template, tname string, data map[string]any, )
Will panic when an error occurs during rendering, make sure you handle panic recovery in a middleware.
func RunServer ¶
Listens for incoming connections and await interrupt signal (or server error) for graceful shutdown
func ServeMonochromeFaviconPNG ¶
func ServeMonochromeFaviconPNG(c color.Color) http.HandlerFunc
Generate and serve a monochrome favicon PNG. Useful for temporary favicon when prototyping.
func ServeRaw ¶
func ServeRaw(v []byte) http.HandlerFunc
func ServeRobotsTXT ¶ added in v0.0.11
func ServeRobotsTXT(disallowedRoutes ...string) http.HandlerFunc
func ServeSitemapXML ¶
func ServeSitemapXML(host string, routes ...string) http.HandlerFunc
Types ¶
type JSONLDWebsiteSchema ¶
type JSONLDWebsiteSchema struct { Context string `json:"@context"` Type struct { Name string `json:"name"` URL string `json:"url"` } `json:"@type"` }
Website JSON+LD schema
type PanicHandler ¶
type PanicHandler func(err any, w http.ResponseWriter, r *http.Request)
type RequestMatcher ¶
RequestMatcher represents a function that reports whether a HTTP request matches a certain criteria.
For example: MatchPath and MatchMethod allow you to match a HTTP request with a certain path and method request to a handler.
func MatchDomainName ¶ added in v0.0.6
func MatchDomainName(s string) RequestMatcher
Matches a certain domain name (SLD + TLD).
func MatchHeader ¶ added in v0.0.6
func MatchHeader(k, v string) RequestMatcher
Matches a certain HTTP header key and value.
func MatchHostname ¶ added in v0.0.6
func MatchHostname(s string) RequestMatcher
Matches a certain host. Ignores port if present.
func MatchMethod ¶
func MatchMethod(methods ...string) RequestMatcher
Checks if the request method is one of the provided ones.
func MatchPath ¶
func MatchPath(path string) RequestMatcher
Checks if the request URL path is the same as the provided one.
func MatchPathPrefix ¶
func MatchPathPrefix(prefix string) RequestMatcher
Checks if the request URL path starts with the provided prefix.
func MatchSubdomain ¶ added in v0.0.6
func MatchSubdomain(s string) RequestMatcher
Matches a certain subdomain.
NB: Treats ccSLD just as normal SLDs (cf. unit test)
type ResponseStatusRecorder ¶ added in v0.1.5
type ResponseStatusRecorder struct { http.ResponseWriter StatusCode int }
func (*ResponseStatusRecorder) WriteHeader ¶ added in v0.1.5
func (srec *ResponseStatusRecorder) WriteHeader(statusCode int)
type Route ¶
type Route struct {
// contains filtered or unexported fields
}
Route represents a HTTP handler with request matchers.