Documentation ¶
Overview ¶
Package httphandle contains reusable code for creating HTTP servers.
Index ¶
- func Attach[A AppSpecific](args AttachArgs[A], a A, mux *http.ServeMux) error
- func ExecuteTemplate(args TemplateArgs, tmplr templater.Templater) error
- func Serve(args ServeArgs, handler http.Handler)
- type API
- type AppSpecific
- type AttachArgs
- type DevDecider
- type General
- type RequestData
- type ServeArgs
- type SetupArgs
- type SetupResults
- type Template
- type TemplateArgs
- type TemplateDataResult
- type TemplateRespMeta
- type WrapperData
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Attach ¶
func Attach[A AppSpecific](args AttachArgs[A], a A, mux *http.ServeMux) error
Attach attaches the handlers to the mux.
func ExecuteTemplate ¶
func ExecuteTemplate(args TemplateArgs, tmplr templater.Templater) error
Types ¶
type API ¶
type API[A AppSpecific] interface { ApplyMiddleware(h http.Handler) http.Handler Authorize(w http.ResponseWriter, r *http.Request) (authorized bool, modified *http.Request) ContentType() (request, response string) HTTPMethod() string Initialize(A) error Respond(r *http.Request) (code int, body []byte, err error) URLPattern() string }
API is an interface for an API handler.
type AppSpecific ¶
type AppSpecific interface { ErrorTemplate(meta TemplateRespMeta, r *http.Request, w http.ResponseWriter) Logger() *slog.Logger NotFound(w http.ResponseWriter, r *http.Request) }
AppSpecific is an interface for the application specific implementations.
type AttachArgs ¶
type AttachArgs[A AppSpecific] struct { API []API[A] Files http.FileSystem General []General[A] MiddlewareOpts middleware.GlobalOptions Template []Template[A] Templater templater.Templater }
AttachArgs are the arguments for attaching handlers to a mux.
type DevDecider ¶
type DevDecider interface {
DevMode() bool
}
DevDecider is a jsontype.Config that determines if the application is in development mode.
type General ¶
type General[A AppSpecific] interface { ApplyMiddleware(h http.Handler) http.Handler Initialize(A) error ServeHTTP(w http.ResponseWriter, r *http.Request) URLPattern() string }
General is an interface for a general handler.
type RequestData ¶
RequestData is the data passed to the template.
type ServeArgs ¶
type ServeArgs struct { Logger *slog.Logger Port uint16 ShutdownFunc func(ctx context.Context) error ShutdownTimeout time.Duration }
ServeArgs are the arguments for the Serve function.
type SetupResults ¶
type SetupResults[C jt.Defaulter[C]] struct { Conf C Files http.FileSystem Logger *slog.Logger Templater templater.Templater }
SetupResults are the results of setting up the application.
type Template ¶
type Template[A AppSpecific] interface { ApplyMiddleware(h http.Handler) http.Handler Authorize(w http.ResponseWriter, r *http.Request) (authorized bool, modified *http.Request, skipTemplate bool) Initialize(A) error Respond(r *http.Request) (meta TemplateRespMeta, templateData any, wrapperData WrapperData) TemplateName() string URLPattern() string WrapperTemplateName() string }
Template is an interface for a template handler.
type TemplateArgs ¶
type TemplateArgs struct { Data any Name string Request *http.Request ResponseCode int WrapperData WrapperData WrapperName string Writer http.ResponseWriter }
TemplateArgs are the arguments passed to the template.
type TemplateDataResult ¶
type TemplateDataResult struct { HeaderAdd template.HTML InnerHTML template.HTML RequestUUID uuid.UUID TemplateArgs TemplateArgs }
TemplateDataResult is the result of executing a template, used for the wrapper template.
type TemplateRespMeta ¶
TemplateRespMeta is the metadata returned from the template.
type WrapperData ¶
type WrapperData interface {
SetResult(result TemplateDataResult)
}
Directories ¶
Path | Synopsis |
---|---|
Package constant contains constants for the application.
|
Package constant contains constants for the application. |
Package middleware provides middleware used by httphandle.
|
Package middleware provides middleware used by httphandle. |
ctxkey
Package ctxkey contains the context keys used by httphandle.
|
Package ctxkey contains the context keys used by httphandle. |