Documentation ¶
Overview ¶
Package eighty is net.http and fasthttp related utility functions.
Index ¶
- Constants
- Variables
- func DumpJSONFasthttp(ctx *fasthttp.RequestCtx, code int, serializable any)
- func GetCookieValue(req *http.Request, name string) (cookieValue string)
- func HasContentTypeFasthttp(r *fasthttp.Request, mimetype string) bool
- func SetCookieValue(key string, expireDuration time.Duration, sessionSecure bool) func(http.ResponseWriter, string, string)
- type CookieWriterFasthttp
- type HandledError
- func (handler HandledError) Error() string
- func (handler HandledError) RenderAPI(ctx *fasthttp.RequestCtx, _ error)
- func (handler HandledError) RenderPage(ctx *fasthttp.RequestCtx, templateRenderer PageRenderer, err error)
- func (handler HandledError) StatusCode() int
- func (handler HandledError) StatusDescription() (msg string)
- func (handler HandledError) StatusMessage() (msg string)
- type PageRenderer
Constants ¶
const ( ContentTypeHeader = "Content-Type" ContentLengthHeader = "Content-Length" EtagHeader = "Etag" UserAgentHeader = "User-Agent" LastModifiedHeader = "Last-Modified" ExpiresHeader = "Expires" CacheControlHeader = "Cache-Control" IfModifiedSince = "If-Modified-Since" IfNoneMatch = "If-None-Match" Server = "Server" VaryHeader = "Vary" ForwardedForIPHeader = "X-Forwarded-For" )
Collection of predefined request header names.
const ( RetryAfterHeader = "Retry-After" LocationHeader = "Location" FrameOptionHeader = "X-Frame-Options" ContentTypeOptionHeader = "X-Content-Type-Options" XssProtectionHeader = "X-XSS-Protection" XCsrfToken = "X-CSRF-Token" XForwardedProto = "X-Forwarded-Proto" )
Collection of predefined response header names.
const ( CacheControlNoCache = "private, no-cache, no-store, no-transform, max-age=0, must-revalidate" ExpiresNone = "0" )
Collection of predefined cache header values.
Variables ¶
var ( HtmlContentUTF8Type = []string{"text/html; charset=utf-8"} HtmlContentType = []string{"text/html"} TextContentType = []string{"text/text"} TextContentUTF8Type = []string{"text/text; charset=utf-8"} UrlencodeContentUTF8Type = []string{"application/x-www-form-urlencoded; charset=utf-8"} UrlencodeContentType = []string{"application/x-www-form-urlencoded"} JsonContentUTF8Type = []string{"application/json; charset=utf-8"} JsonContentType = []string{"application/json"} )
Collection of predefined mime types.
var ( FrameOptionDeny = []string{"DENY"} FrameOptionSameOrigin = []string{"SAMEORIGIN"} ContentTypeOptionNoSniffing = []string{"nosniff"} XssProtectionBlocking = []string{"1; mode=block"} )
Collection of predefined CSRF header values.
var ( MethodHEAD = []byte("HEAD") MethodGET = []byte("GET") MethodPOST = []byte("POST") )
Collection of predefined http method names.
Functions ¶
func DumpJSONFasthttp ¶
func DumpJSONFasthttp(ctx *fasthttp.RequestCtx, code int, serializable any)
DumpJSONFasthttp is a simple JSON renderer for the fasthttp.
func GetCookieValue ¶
GetCookieValue is the simple cookie getter.
func HasContentTypeFasthttp ¶
HasContentTypeFasthttp is a simple checker that checks if an incoming request satisfies a given mime-type.
func SetCookieValue ¶
func SetCookieValue(key string, expireDuration time.Duration, sessionSecure bool) func(http.ResponseWriter, string, string)
SetCookieValue is a useful cookie generator for net.http.
Types ¶
type CookieWriterFasthttp ¶
func NewCookieWriter ¶
func NewCookieWriter(key string, expireDuration time.Duration, secured bool) CookieWriterFasthttp
NewCookieWriter is a useful cookie generator for fasthttp.
type HandledError ¶
type HandledError int
HandledError is a http status handler type
const ( // HandledErrorBadRequest : 400, BadRequest http status HandledErrorBadRequest HandledError = 400 HandledErrorUnauthorized HandledError = 401 // HandledErrorForbidden : 403, Forbidden http status HandledErrorForbidden HandledError = 403 // HandledErrorNotFound : 404, NotFound http status HandledErrorNotFound HandledError = 404 // HandledErrorMethodNotAllowed : 405, MethodNotAllowed http status HandledErrorMethodNotAllowed HandledError = 405 // HandledErrorNotAcceptable : 406, NotAcceptable http status HandledErrorNotAcceptable HandledError = 406 // HandledErrorRequestTimeout : 408, RequestTimeout http status HandledErrorRequestTimeout HandledError = 408 // HandledErrorGone : 410, Gone http status HandledErrorGone HandledError = 410 // HandledErrorTooManyRequests : 429, TooManyRequests http status HandledErrorTooManyRequests HandledError = 429 // HandledErrorInternalServerError : 500, InternalServerError http status HandledErrorInternalServerError HandledError = 500 // HandledErrorNotImplemented : 501, NotImplemented http status HandledErrorNotImplemented HandledError = 501 // HandledErrorBadGateway : 502, BadGateway http status HandledErrorBadGateway HandledError = 502 HandledErrorServiceUnavailable HandledError = 503 // HandledErrorGatewayTimeout : 504, GatewayTimeout http status HandledErrorGatewayTimeout HandledError = 504 )
Collection of predefined HandledError.
func HandledErrorCodeOf ¶
func HandledErrorCodeOf(value int) (HandledError, bool)
HandledErrorCodeOf is the conversion function with the http status code to HandledError.
func HandledErrorOf ¶
func HandledErrorOf(value any) (HandledError, bool)
HandledErrorOf is the conversion function with the generic error object to HandledError.
func WrapHandledError ¶
func WrapHandledError(panicObj any) (handler HandledError, err error)
WrapHandledError is the panic handler function with a thrown panic object.
func (HandledError) Error ¶
func (handler HandledError) Error() string
Error implements the built-in interface type error.
func (HandledError) RenderAPI ¶
func (handler HandledError) RenderAPI(ctx *fasthttp.RequestCtx, _ error)
RenderAPI is a json renderer function, that follows the http status code with context.
func (HandledError) RenderPage ¶
func (handler HandledError) RenderPage(ctx *fasthttp.RequestCtx, templateRenderer PageRenderer, err error)
RenderPage is a html page renderer function, that follows the http status code with context.
func (HandledError) StatusCode ¶
func (handler HandledError) StatusCode() int
StatusCode returns the http status code.
func (HandledError) StatusDescription ¶
func (handler HandledError) StatusDescription() (msg string)
StatusDescription returns the http status description.
func (HandledError) StatusMessage ¶
func (handler HandledError) StatusMessage() (msg string)
StatusMessage returns the http status message.
type PageRenderer ¶
PageRenderer is a function interface type for the http status page renderer.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package client provides some customizable http client.
|
Package client provides some customizable http client. |
Package middleware provides the collection of processing filters for the http request.
|
Package middleware provides the collection of processing filters for the http request. |
Package routing provides the name resolving utility for the fasthttp.
|
Package routing provides the name resolving utility for the fasthttp. |
Package serve provides static file serving functions.
|
Package serve provides static file serving functions. |