Documentation
¶
Index ¶
- Constants
- Variables
- func BodyAs[T any](r *http.Request) (T, error)
- func BodyReadAll(r *http.Request) ([]byte, error)
- func DecryptCookie[T any](opts SecureCookieParams) (*T, error)
- func DefaultCookieEncSecret() []byte
- func DefaultCookieSigningSecret() []byte
- func EncryptCookie(opts SecureCookieParams) (*http.Cookie, error)
- func HasBody(r *http.Request) bool
- func IsSecure(r *http.Request) bool
- func NativeHandlerFunc(h HandlerFunc) http.HandlerFunc
- func ProxyBaseURL(r *http.Request) url.URL
- func ProxyURLFull(r *http.Request) url.URL
- type ContentType
- type ErrCtx
- type Error
- type HandlerFunc
- type ResMap
- type ResponseWriter
- type SecureCookieParams
Constants ¶
View Source
const (
XForwardedFor = "X-Forwarded-Proto"
)
Variables ¶
View Source
var ( ErrInternalServer = Error{ Message: "internal server error", Code: "INTERNAL_SERVER_ERROR", Status: http.StatusInternalServerError, } ErrNotFound = Error{ Message: "resource not found", Code: "NOT_FOUND_ERROR", Status: http.StatusNotFound, } Message: "unauthorized", Code: "UNAUTHORIZED", Status: http.StatusUnauthorized, } ErrBadRequest = Error{ Message: "bad request", Code: "BAD_REQUEST", Status: http.StatusBadRequest, } )
View Source
var (
ErrNoHTTPBody = errors.New("no http body bytes to read")
)
Functions ¶
func DecryptCookie ¶
func DecryptCookie[T any](opts SecureCookieParams) (*T, error)
func DefaultCookieEncSecret ¶
func DefaultCookieEncSecret() []byte
func DefaultCookieSigningSecret ¶
func DefaultCookieSigningSecret() []byte
func EncryptCookie ¶
func EncryptCookie(opts SecureCookieParams) (*http.Cookie, error)
func NativeHandlerFunc ¶
func NativeHandlerFunc(h HandlerFunc) http.HandlerFunc
Types ¶
type ContentType ¶
type ContentType string
const ( TextHTML ContentType = "text/html; charset=utf-8" ApplicationJSON ContentType = "application/json; charset=utf-8" ApplicationXML ContentType = "application/xml; charset=utf-8" )
type Error ¶
type Error struct {
Message string `json:"message"`
Code string `json:"code"`
Context ResMap `json:"context"`
Err error `json:"-"`
Status int `json:"-"`
}
func (Error) WithErrCtx ¶
func (Error) WithMessage ¶
type HandlerFunc ¶
type HandlerFunc func(w ResponseWriter, r *http.Request) error
func (HandlerFunc) ServeHTTP ¶
func (h HandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request)
type ResponseWriter ¶
type ResponseWriter interface {
Status(code int) ResponseWriter
ContentType(media ContentType) ResponseWriter
Send(a ...any) error
JSON(v any) error
XML(v any) error
JSONErr(err Error) error
XMLErr(err Error) error
Header() http.Header
Write(bytes []byte) (int, error)
WriteHeader(statusCode int)
Redirect(r *http.Request, url string, code int)
SetCookie(cookie http.Cookie) ResponseWriter
DelCookie(cookie http.Cookie) ResponseWriter
DelCookieByName(name string) ResponseWriter
}
func NewResponseWriter ¶
func NewResponseWriter(w http.ResponseWriter) ResponseWriter
Click to show internal directories.
Click to hide internal directories.