Documentation ¶
Index ¶
- Constants
- func NewHTTPAccessLogMiddleware(cb func(AccessLogRequestData)) func(http.Handler) http.Handler
- func RespondJSON(w http.ResponseWriter, status int, v any) error
- func RespondText(w http.ResponseWriter, status int, s string) error
- type AccessLogRequestData
- type GorillaRouter
- func (gorillaRouter *GorillaRouter) HandleEndpoint(path, method string, handlerFunc http.HandlerFunc)
- func (gorillaRouter *GorillaRouter) HandlePrefix(path string, handler http.Handler)
- func (gorillaRouter *GorillaRouter) ParseURIParams(r *http.Request) map[string]string
- func (gorillaRouter *GorillaRouter) ServeHTTP(w http.ResponseWriter, r *http.Request)
- type PrefixRouter
- type PrefixRouterConfig
- type Recorder
- type Router
- type Sitemap
- type SitemapURL
- type StaticWebsite
- type StaticWebsiteConfig
Constants ¶
View Source
const ( HeaderContentType = "Content-Type" ContentTypeJSON = "application/json" ContentTypePlainText = "text/plain; charset=utf-8" )
Variables ¶
This section is empty.
Functions ¶
func NewHTTPAccessLogMiddleware ¶ added in v0.0.1
func NewHTTPAccessLogMiddleware(cb func(AccessLogRequestData)) func(http.Handler) http.Handler
func RespondJSON ¶
func RespondJSON(w http.ResponseWriter, status int, v any) error
Writes a JSON response.
func RespondText ¶
func RespondText(w http.ResponseWriter, status int, s string) error
Writes a plain text response
Types ¶
type AccessLogRequestData ¶ added in v0.0.3
type GorillaRouter ¶
type GorillaRouter struct {
// contains filtered or unexported fields
}
func NewGorillaRouter ¶
func NewGorillaRouter() *GorillaRouter
func (*GorillaRouter) HandleEndpoint ¶
func (gorillaRouter *GorillaRouter) HandleEndpoint(path, method string, handlerFunc http.HandlerFunc)
func (*GorillaRouter) HandlePrefix ¶
func (gorillaRouter *GorillaRouter) HandlePrefix(path string, handler http.Handler)
func (*GorillaRouter) ParseURIParams ¶
func (gorillaRouter *GorillaRouter) ParseURIParams(r *http.Request) map[string]string
func (*GorillaRouter) ServeHTTP ¶
func (gorillaRouter *GorillaRouter) ServeHTTP(w http.ResponseWriter, r *http.Request)
type PrefixRouter ¶
type PrefixRouter struct {
// contains filtered or unexported fields
}
PrefixRouter handles requests for a website and a backend API.
func NewPrefixRouter ¶
func NewPrefixRouter(config PrefixRouterConfig) (*PrefixRouter, error)
func (*PrefixRouter) ServeHTTP ¶
func (h *PrefixRouter) ServeHTTP(w http.ResponseWriter, r *http.Request)
This function routes requests to the appropriate handler depending if they are for the backend API or the file server (= website files).
type PrefixRouterConfig ¶
type PrefixRouterConfig struct { PathPrefix string HandlerWithPrefix http.Handler HandlerWithoutPrefix http.Handler }
func (PrefixRouterConfig) Validate ¶
func (c PrefixRouterConfig) Validate() error
type Recorder ¶
type Recorder struct { http.ResponseWriter StatusCode int NumBodyBytesWritten int }
Recorder implements the http.ResponseWriter interface. It stores data about the current request / response and forwards it to the underlying response writer
func (*Recorder) WriteHeader ¶
type Sitemap ¶ added in v0.0.1
type Sitemap struct {
URLSet []SitemapURL `xml:"urlset"`
}
type SitemapURL ¶ added in v0.0.1
type StaticWebsite ¶ added in v0.0.1
type StaticWebsite struct {
// contains filtered or unexported fields
}
func NewStaticWebsite ¶ added in v0.0.1
func NewStaticWebsite(c StaticWebsiteConfig) (*StaticWebsite, error)
subFS: Set it to "." for current dir
func (*StaticWebsite) HTTPHandler ¶ added in v0.0.1
func (sw *StaticWebsite) HTTPHandler() (string, http.Handler)
func (*StaticWebsite) ServeHTTP ¶ added in v0.0.1
func (h *StaticWebsite) ServeHTTP(w http.ResponseWriter, r *http.Request)
type StaticWebsiteConfig ¶ added in v0.0.1
type StaticWebsiteConfig struct { Fsys fs.FS // static file system SubDir string // "." for current directory FallbackPagePath string // ex: "404.html" }
func (StaticWebsiteConfig) Validate ¶ added in v0.0.1
func (c StaticWebsiteConfig) Validate() error
Click to show internal directories.
Click to hide internal directories.