Documentation
¶
Index ¶
- Constants
- func BadRequest(w http.ResponseWriter, err error)
- func ParseJsonRequest[T any](r *http.Request) (*T, error)
- type BodyOption
- type ErrorResponse
- type HeaderOption
- type JsonBodyOption
- type MuxBuilder
- type MuxOption
- type Response
- type ResponseOption
- type Route
- type Server
- type StatusOption
- type Visibility
Constants ¶
View Source
const ( DefaultAllowHeader = "Access-Control-Allow-Origin, Content-Type, Authorization" AllowOriginHeader = "Access-Control-Allow-Origin" AllowMethodsHeader = "Access-Control-Allow-Methods" AllowHeadersHeader = "Access-Control-Allow-Headers" AllowOriginValue = "*" )
View Source
const ( HeaderContentType = "Content-Type" TypeApplicationJson = "application/json" DefaultHttpStatus = http.StatusOK )
View Source
const ( ServerDefaultTimeOut = 10 * time.Second ServerWriteTimeOut = ServerDefaultTimeOut ServerReadTimeOut = ServerDefaultTimeOut )
Variables ¶
This section is empty.
Functions ¶
func BadRequest ¶ added in v1.3.0
func BadRequest(w http.ResponseWriter, err error)
Types ¶
type BodyOption ¶
type BodyOption struct {
// contains filtered or unexported fields
}
func (BodyOption) Apply ¶
func (p BodyOption) Apply(response *Response)
type ErrorResponse ¶ added in v1.3.1
type ErrorResponse struct {
Error string `json:"error"`
}
func NewErrorResponse ¶ added in v1.3.1
func NewErrorResponse(err error) *ErrorResponse
type HeaderOption ¶
type HeaderOption struct {
// contains filtered or unexported fields
}
func (HeaderOption) Apply ¶
func (h HeaderOption) Apply(response *Response)
type JsonBodyOption ¶
type JsonBodyOption struct {
ResponseOption
// contains filtered or unexported fields
}
func (JsonBodyOption) Apply ¶
func (jp JsonBodyOption) Apply(response *Response)
type MuxBuilder ¶
type MuxBuilder struct {
// contains filtered or unexported fields
}
func NewMuxBuilder ¶
func NewMuxBuilder(logger *slog.Logger, opts ...MuxOption) *MuxBuilder
type Response ¶
func NewJsonResponse ¶
func NewJsonResponse(v any, opts ...ResponseOption) *Response
func NewResponse ¶
func NewResponse(opts ...ResponseOption) *Response
NewResponse creates a Response with default attributes: Status=200 Body=empty byte slice Headers=empty hashmap
func (*Response) Write ¶
func (r *Response) Write(w http.ResponseWriter)
Write sends the Response's content to the http.ResponseWriter.
type ResponseOption ¶
type ResponseOption interface {
Apply(response *Response)
}
func WithContentTypeJson ¶
func WithContentTypeJson() ResponseOption
WithContentTypeJson tells the Response its content-Type will be "application/json"
func WithHeader ¶
func WithHeader(name, value string) ResponseOption
WithHeader adds a header to the Response. Invoke WithHeader as many times as you have headers to set.
func WithJsonBody ¶
func WithJsonBody(v any) ResponseOption
WithJsonBody takes an object meant to be translated to JSON inside the response's body and sets the content-type to "application/json"
func WithStatus ¶
func WithStatus(code int) ResponseOption
type Route ¶
type Route struct {
// contains filtered or unexported fields
}
func NewRouteFunc ¶
func NewRouteFunc(v Visibility, p string, f func(http.ResponseWriter, *http.Request)) *Route
type StatusOption ¶
type StatusOption struct {
// contains filtered or unexported fields
}
func (StatusOption) Apply ¶
func (s StatusOption) Apply(response *Response)
Click to show internal directories.
Click to hide internal directories.