eighty

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 24, 2022 License: BSD-3-Clause Imports: 10 Imported by: 0

README

eighty

GoDoc Go Report

Description

net.http and fasthttp related utility functions.

Requirements

Go 1.5 or above.

Installation

Run the following command to install the package:

go get amuz.es/src/go/eighty

Getting Started

TBD

Documentation

Overview

Package eighty is net.http and fasthttp related utility functions.

Index

Constants

View Source
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.

View Source
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.

View Source
const (
	CacheControlNoCache = "private, no-cache, no-store, no-transform, max-age=0, must-revalidate"
	ExpiresNone         = "0"
)

Collection of predefined cache header values.

Variables

View Source
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.

View Source
var (
	FrameOptionDeny       = []string{"DENY"}
	FrameOptionSameOrigin = []string{"SAMEORIGIN"}

	ContentTypeOptionNoSniffing = []string{"nosniff"}
	XssProtectionBlocking       = []string{"1; mode=block"}
)

Collection of predefined CSRF header values.

View Source
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

func GetCookieValue(req *http.Request, name string) (cookieValue string)

GetCookieValue is the simple cookie getter.

func HasContentTypeFasthttp

func HasContentTypeFasthttp(r *fasthttp.Request, mimetype string) bool

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

type CookieWriterFasthttp func(*fasthttp.Response, []byte, string)

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 : 401, Unauthorized http status
	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 : 503, ServiceUnavailable http status
	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

type PageRenderer = func(r *fasthttp.RequestCtx, name string, context map[string]any) error

PageRenderer is a function interface type for the http status page renderer.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL