Back to godoc.org
github.com/gofiber/fiber

package fiber

v1.10.5
Latest Go to latest
Published: 1 day ago | License: MIT | Module: github.com/gofiber/fiber

Index

Constants

const (
	MethodGet     = "GET"     // RFC 7231, 4.3.1
	MethodHead    = "HEAD"    // RFC 7231, 4.3.2
	MethodPost    = "POST"    // RFC 7231, 4.3.3
	MethodPut     = "PUT"     // RFC 7231, 4.3.4
	MethodPatch   = "PATCH"   // RFC 5789
	MethodDelete  = "DELETE"  // RFC 7231, 4.3.5
	MethodConnect = "CONNECT" // RFC 7231, 4.3.6
	MethodOptions = "OPTIONS" // RFC 7231, 4.3.7
	MethodTrace   = "TRACE"   // RFC 7231, 4.3.8
)

HTTP methods were copied from net/http.

const (
	MIMETextXML               = "text/xml"
	MIMETextHTML              = "text/html"
	MIMETextPlain             = "text/plain"
	MIMEApplicationJSON       = "application/json"
	MIMEApplicationJavaScript = "application/javascript"
	MIMEApplicationXML        = "application/xml"
	MIMEApplicationForm       = "application/x-www-form-urlencoded"
	MIMEMultipartForm         = "multipart/form-data"
	MIMEOctetStream           = "application/octet-stream"
)

MIME types that are commonly used

const (
	StatusContinue                      = 100 // RFC 7231, 6.2.1
	StatusSwitchingProtocols            = 101 // RFC 7231, 6.2.2
	StatusProcessing                    = 102 // RFC 2518, 10.1
	StatusEarlyHints                    = 103 // RFC 8297
	StatusOK                            = 200 // RFC 7231, 6.3.1
	StatusCreated                       = 201 // RFC 7231, 6.3.2
	StatusAccepted                      = 202 // RFC 7231, 6.3.3
	StatusNonAuthoritativeInfo          = 203 // RFC 7231, 6.3.4
	StatusNoContent                     = 204 // RFC 7231, 6.3.5
	StatusResetContent                  = 205 // RFC 7231, 6.3.6
	StatusPartialContent                = 206 // RFC 7233, 4.1
	StatusMultiStatus                   = 207 // RFC 4918, 11.1
	StatusAlreadyReported               = 208 // RFC 5842, 7.1
	StatusIMUsed                        = 226 // RFC 3229, 10.4.1
	StatusMultipleChoices               = 300 // RFC 7231, 6.4.1
	StatusMovedPermanently              = 301 // RFC 7231, 6.4.2
	StatusFound                         = 302 // RFC 7231, 6.4.3
	StatusSeeOther                      = 303 // RFC 7231, 6.4.4
	StatusNotModified                   = 304 // RFC 7232, 4.1
	StatusUseProxy                      = 305 // RFC 7231, 6.4.5
	StatusTemporaryRedirect             = 307 // RFC 7231, 6.4.7
	StatusPermanentRedirect             = 308 // RFC 7538, 3
	StatusBadRequest                    = 400 // RFC 7231, 6.5.1
	StatusUnauthorized                  = 401 // RFC 7235, 3.1
	StatusPaymentRequired               = 402 // RFC 7231, 6.5.2
	StatusForbidden                     = 403 // RFC 7231, 6.5.3
	StatusNotFound                      = 404 // RFC 7231, 6.5.4
	StatusMethodNotAllowed              = 405 // RFC 7231, 6.5.5
	StatusNotAcceptable                 = 406 // RFC 7231, 6.5.6
	StatusProxyAuthRequired             = 407 // RFC 7235, 3.2
	StatusRequestTimeout                = 408 // RFC 7231, 6.5.7
	StatusConflict                      = 409 // RFC 7231, 6.5.8
	StatusGone                          = 410 // RFC 7231, 6.5.9
	StatusLengthRequired                = 411 // RFC 7231, 6.5.10
	StatusPreconditionFailed            = 412 // RFC 7232, 4.2
	StatusRequestEntityTooLarge         = 413 // RFC 7231, 6.5.11
	StatusRequestURITooLong             = 414 // RFC 7231, 6.5.12
	StatusUnsupportedMediaType          = 415 // RFC 7231, 6.5.13
	StatusRequestedRangeNotSatisfiable  = 416 // RFC 7233, 4.4
	StatusExpectationFailed             = 417 // RFC 7231, 6.5.14
	StatusTeapot                        = 418 // RFC 7168, 2.3.3
	StatusMisdirectedRequest            = 421 // RFC 7540, 9.1.2
	StatusUnprocessableEntity           = 422 // RFC 4918, 11.2
	StatusLocked                        = 423 // RFC 4918, 11.3
	StatusFailedDependency              = 424 // RFC 4918, 11.4
	StatusTooEarly                      = 425 // RFC 8470, 5.2.
	StatusUpgradeRequired               = 426 // RFC 7231, 6.5.15
	StatusPreconditionRequired          = 428 // RFC 6585, 3
	StatusTooManyRequests               = 429 // RFC 6585, 4
	StatusRequestHeaderFieldsTooLarge   = 431 // RFC 6585, 5
	StatusUnavailableForLegalReasons    = 451 // RFC 7725, 3
	StatusInternalServerError           = 500 // RFC 7231, 6.6.1
	StatusNotImplemented                = 501 // RFC 7231, 6.6.2
	StatusBadGateway                    = 502 // RFC 7231, 6.6.3
	StatusServiceUnavailable            = 503 // RFC 7231, 6.6.4
	StatusGatewayTimeout                = 504 // RFC 7231, 6.6.5
	StatusHTTPVersionNotSupported       = 505 // RFC 7231, 6.6.6
	StatusVariantAlsoNegotiates         = 506 // RFC 2295, 8.1
	StatusInsufficientStorage           = 507 // RFC 4918, 11.5
	StatusLoopDetected                  = 508 // RFC 5842, 7.2
	StatusNotExtended                   = 510 // RFC 2774, 7
	StatusNetworkAuthenticationRequired = 511 // RFC 6585, 6
)

HTTP status codes were copied from net/http.

const (
	HeaderAuthorization                   = "Authorization"
	HeaderProxyAuthenticate               = "Proxy-Authenticate"
	HeaderProxyAuthorization              = "Proxy-Authorization"
	HeaderWWWAuthenticate                 = "WWW-Authenticate"
	HeaderAge                             = "Age"
	HeaderCacheControl                    = "Cache-Control"
	HeaderClearSiteData                   = "Clear-Site-Data"
	HeaderExpires                         = "Expires"
	HeaderPragma                          = "Pragma"
	HeaderWarning                         = "Warning"
	HeaderAcceptCH                        = "Accept-CH"
	HeaderAcceptCHLifetime                = "Accept-CH-Lifetime"
	HeaderContentDPR                      = "Content-DPR"
	HeaderDPR                             = "DPR"
	HeaderEarlyData                       = "Early-Data"
	HeaderSaveData                        = "Save-Data"
	HeaderViewportWidth                   = "Viewport-Width"
	HeaderWidth                           = "Width"
	HeaderETag                            = "ETag"
	HeaderIfMatch                         = "If-Match"
	HeaderIfModifiedSince                 = "If-Modified-Since"
	HeaderIfNoneMatch                     = "If-None-Match"
	HeaderIfUnmodifiedSince               = "If-Unmodified-Since"
	HeaderLastModified                    = "Last-Modified"
	HeaderVary                            = "Vary"
	HeaderConnection                      = "Connection"
	HeaderKeepAlive                       = "Keep-Alive"
	HeaderAccept                          = "Accept"
	HeaderAcceptCharset                   = "Accept-Charset"
	HeaderAcceptEncoding                  = "Accept-Encoding"
	HeaderAcceptLanguage                  = "Accept-Language"
	HeaderCookie                          = "Cookie"
	HeaderExpect                          = "Expect"
	HeaderMaxForwards                     = "Max-Forwards"
	HeaderSetCookie                       = "Set-Cookie"
	HeaderAccessControlAllowCredentials   = "Access-Control-Allow-Credentials"
	HeaderAccessControlAllowHeaders       = "Access-Control-Allow-Headers"
	HeaderAccessControlAllowMethods       = "Access-Control-Allow-Methods"
	HeaderAccessControlAllowOrigin        = "Access-Control-Allow-Origin"
	HeaderAccessControlExposeHeaders      = "Access-Control-Expose-Headers"
	HeaderAccessControlMaxAge             = "Access-Control-Max-Age"
	HeaderAccessControlRequestHeaders     = "Access-Control-Request-Headers"
	HeaderAccessControlRequestMethod      = "Access-Control-Request-Method"
	HeaderOrigin                          = "Origin"
	HeaderTimingAllowOrigin               = "Timing-Allow-Origin"
	HeaderXPermittedCrossDomainPolicies   = "X-Permitted-Cross-Domain-Policies"
	HeaderDNT                             = "DNT"
	HeaderTk                              = "Tk"
	HeaderContentDisposition              = "Content-Disposition"
	HeaderContentEncoding                 = "Content-Encoding"
	HeaderContentLanguage                 = "Content-Language"
	HeaderContentLength                   = "Content-Length"
	HeaderContentLocation                 = "Content-Location"
	HeaderContentType                     = "Content-Type"
	HeaderForwarded                       = "Forwarded"
	HeaderVia                             = "Via"
	HeaderXForwardedFor                   = "X-Forwarded-For"
	HeaderXForwardedHost                  = "X-Forwarded-Host"
	HeaderXForwardedProto                 = "X-Forwarded-Proto"
	HeaderXForwardedProtocol              = "X-Forwarded-Protocol"
	HeaderXForwardedSsl                   = "X-Forwarded-Ssl"
	HeaderXUrlScheme                      = "X-Url-Scheme"
	HeaderLocation                        = "Location"
	HeaderFrom                            = "From"
	HeaderHost                            = "Host"
	HeaderReferer                         = "Referer"
	HeaderReferrerPolicy                  = "Referrer-Policy"
	HeaderUserAgent                       = "User-Agent"
	HeaderAllow                           = "Allow"
	HeaderServer                          = "Server"
	HeaderAcceptRanges                    = "Accept-Ranges"
	HeaderContentRange                    = "Content-Range"
	HeaderIfRange                         = "If-Range"
	HeaderRange                           = "Range"
	HeaderContentSecurityPolicy           = "Content-Security-Policy"
	HeaderContentSecurityPolicyReportOnly = "Content-Security-Policy-Report-Only"
	HeaderCrossOriginResourcePolicy       = "Cross-Origin-Resource-Policy"
	HeaderExpectCT                        = "Expect-CT"
	HeaderFeaturePolicy                   = "Feature-Policy"
	HeaderPublicKeyPins                   = "Public-Key-Pins"
	HeaderPublicKeyPinsReportOnly         = "Public-Key-Pins-Report-Only"
	HeaderStrictTransportSecurity         = "Strict-Transport-Security"
	HeaderUpgradeInsecureRequests         = "Upgrade-Insecure-Requests"
	HeaderXContentTypeOptions             = "X-Content-Type-Options"
	HeaderXDownloadOptions                = "X-Download-Options"
	HeaderXFrameOptions                   = "X-Frame-Options"
	HeaderXPoweredBy                      = "X-Powered-By"
	HeaderXXSSProtection                  = "X-XSS-Protection"
	HeaderLastEventID                     = "Last-Event-ID"
	HeaderNEL                             = "NEL"
	HeaderPingFrom                        = "Ping-From"
	HeaderPingTo                          = "Ping-To"
	HeaderReportTo                        = "Report-To"
	HeaderTE                              = "TE"
	HeaderTrailer                         = "Trailer"
	HeaderTransferEncoding                = "Transfer-Encoding"
	HeaderSecWebSocketAccept              = "Sec-WebSocket-Accept"
	HeaderSecWebSocketExtensions          = "Sec-WebSocket-Extensions"
	HeaderSecWebSocketKey                 = "Sec-WebSocket-Key"
	HeaderSecWebSocketProtocol            = "Sec-WebSocket-Protocol"
	HeaderSecWebSocketVersion             = "Sec-WebSocket-Version"
	HeaderAcceptPatch                     = "Accept-Patch"
	HeaderAcceptPushPolicy                = "Accept-Push-Policy"
	HeaderAcceptSignature                 = "Accept-Signature"
	HeaderAltSvc                          = "Alt-Svc"
	HeaderDate                            = "Date"
	HeaderIndex                           = "Index"
	HeaderLargeAllocation                 = "Large-Allocation"
	HeaderLink                            = "Link"
	HeaderPushPolicy                      = "Push-Policy"
	HeaderRetryAfter                      = "Retry-After"
	HeaderServerTiming                    = "Server-Timing"
	HeaderSignature                       = "Signature"
	HeaderSignedHeaders                   = "Signed-Headers"
	HeaderSourceMap                       = "SourceMap"
	HeaderUpgrade                         = "Upgrade"
	HeaderXDNSPrefetchControl             = "X-DNS-Prefetch-Control"
	HeaderXPingback                       = "X-Pingback"
	HeaderXRequestID                      = "X-Request-ID"
	HeaderXRequestedWith                  = "X-Requested-With"
	HeaderXRobotsTag                      = "X-Robots-Tag"
	HeaderXUACompatible                   = "X-UA-Compatible"
)

HTTP Headers were copied from net/http.

const Version = "1.10.5"

Version of current package

type App

type App struct {

	// App settings
	Settings *Settings
	// contains filtered or unexported fields
}

App denotes the Fiber application.

func New

func New(settings ...*Settings) *App

New creates a new Fiber named instance. You can pass optional settings when creating a new instance.

func (*App) AcquireCtx

func (app *App) AcquireCtx(fctx *fasthttp.RequestCtx) *Ctx

AcquireCtx from pool

func (*App) Add

func (app *App) Add(method, path string, handlers ...Handler) *Route

Add ...

func (*App) All

func (app *App) All(path string, handlers ...Handler) []*Route

All ...

func (*App) Connect

func (app *App) Connect(path string, handlers ...Handler) *Route

Connect ...

func (*App) Delete

func (app *App) Delete(path string, handlers ...Handler) *Route

Delete ...

func (*App) Get

func (app *App) Get(path string, handlers ...Handler) *Route

Get ...

func (*App) Group

func (app *App) Group(prefix string, handlers ...Handler) *Group

Group is used for Routes with common prefix to define a new sub-router with optional middleware.

func (*App) Head

func (app *App) Head(path string, handlers ...Handler) *Route

Head ...

func (*App) Listen

func (app *App) Listen(address interface{}, tlsconfig ...*tls.Config) error

Listen serves HTTP requests from the given addr or port. You can pass an optional *tls.Config to enable TLS.

func (*App) Options

func (app *App) Options(path string, handlers ...Handler) *Route

Options ...

func (*App) Patch

func (app *App) Patch(path string, handlers ...Handler) *Route

Patch ...

func (*App) Post

func (app *App) Post(path string, handlers ...Handler) *Route

Post ...

func (*App) Put

func (app *App) Put(path string, handlers ...Handler) *Route

Put ...

func (*App) ReleaseCtx

func (app *App) ReleaseCtx(ctx *Ctx)

ReleaseCtx to pool

func (*App) Serve

func (app *App) Serve(ln net.Listener, tlsconfig ...*tls.Config) error

Serve can be used to pass a custom listener This method does not support the Prefork feature Preforkin is not available using app.Serve(ln net.Listener) You can pass an optional *tls.Config to enable TLS.

func (*App) Shutdown

func (app *App) Shutdown() error

Shutdown gracefully shuts down the server without interrupting any active connections. Shutdown works by first closing all open listeners and then waiting indefinitely for all connections to return to idle and then shut down.

When Shutdown is called, Serve, ListenAndServe, and ListenAndServeTLS immediately return nil. Make sure the program doesn't exit and waits instead for Shutdown to return.

Shutdown does not close keepalive connections so its recommended to set ReadTimeout to something else than 0.

func (*App) Static

func (app *App) Static(prefix, root string, config ...Static) *Route

Static ...

func (*App) Test

func (app *App) Test(request *http.Request, msTimeout ...int) (*http.Response, error)

Test is used for internal debugging by passing a *http.Request Timeout is optional and defaults to 1s, -1 will disable it completely.

func (*App) Trace

func (app *App) Trace(path string, handlers ...Handler) *Route

Trace ...

func (*App) Use

func (app *App) Use(args ...interface{}) *Route

Use registers a middleware route. Middleware matches requests beginning with the provided prefix. Providing a prefix is optional, it defaults to "/".

- app.Use(handler) - app.Use("/api", handler) - app.Use("/api", handler, handler)

type Cookie struct {
	Name     string
	Value    string
	Path     string
	Domain   string
	Expires  time.Time
	Secure   bool
	HTTPOnly bool
	SameSite string
}

Cookie data for ctx.Cookie

type Ctx

type Ctx struct {
	Fasthttp *fasthttp.RequestCtx // Reference to *fasthttp.RequestCtx
	// contains filtered or unexported fields
}

Ctx represents the Context which hold the HTTP request and response. It has methods for the request query string, parameters, body, HTTP headers and so on.

func (*Ctx) Accepts

func (ctx *Ctx) Accepts(offers ...string) string

Accepts checks if the specified extensions or content types are acceptable.

func (*Ctx) AcceptsCharsets

func (ctx *Ctx) AcceptsCharsets(offers ...string) string

AcceptsCharsets checks if the specified charset is acceptable.

func (*Ctx) AcceptsEncodings

func (ctx *Ctx) AcceptsEncodings(offers ...string) string

AcceptsEncodings checks if the specified encoding is acceptable.

func (*Ctx) AcceptsLanguages

func (ctx *Ctx) AcceptsLanguages(offers ...string) string

AcceptsLanguages checks if the specified language is acceptable.

func (*Ctx) Append

func (ctx *Ctx) Append(field string, values ...string)

Append the specified value to the HTTP response header field. If the header is not already set, it creates the header with the specified value.

func (*Ctx) Attachment

func (ctx *Ctx) Attachment(filename ...string)

Attachment sets the HTTP response Content-Disposition header field to attachment.

func (*Ctx) BaseURL

func (ctx *Ctx) BaseURL() string

BaseURL returns (protocol + host + base path).

func (*Ctx) Body

func (ctx *Ctx) Body() string

Body contains the raw body submitted in a POST request. Returned value is only valid within the handler. Do not store any references. Make copies or use the Immutable setting instead.

func (*Ctx) BodyParser

func (ctx *Ctx) BodyParser(out interface{}) error

BodyParser binds the request body to a struct. It supports decoding the following content types based on the Content-Type header: application/json, application/xml, application/x-www-form-urlencoded, multipart/form-data

func (*Ctx) ClearCookie

func (ctx *Ctx) ClearCookie(key ...string)

ClearCookie expires a specific cookie by key on the client side. If no key is provided it expires all cookies that came with the request.

func (*Ctx) Context

func (ctx *Ctx) Context() context.Context

Context returns context.Context that carries a deadline, a cancellation signal, and other values across API boundaries.

func (*Ctx) Cookie

func (ctx *Ctx) Cookie(cookie *Cookie)

Cookie sets a cookie by passing a cookie struct

func (*Ctx) Cookies

func (ctx *Ctx) Cookies(key string) (value string)

Cookies is used for getting a cookie value by key Returned value is only valid within the handler. Do not store any references. Make copies or use the Immutable setting instead.

func (*Ctx) Download

func (ctx *Ctx) Download(file string, filename ...string)

Download transfers the file from path as an attachment. Typically, browsers will prompt the user for download. By default, the Content-Disposition header filename= parameter is the filepath (this typically appears in the browser dialog). Override this default with the filename parameter.

func (*Ctx) Error

func (ctx *Ctx) Error() error

Error contains the error information passed via the Next(err) method.

func (*Ctx) FormFile

func (ctx *Ctx) FormFile(key string) (*multipart.FileHeader, error)

FormFile returns the first file by key from a MultipartForm.

func (*Ctx) FormValue

func (ctx *Ctx) FormValue(key string) (value string)

FormValue returns the first value by key from a MultipartForm. Returned value is only valid within the handler. Do not store any references. Make copies or use the Immutable setting instead.

func (*Ctx) Format

func (ctx *Ctx) Format(body interface{})

Format performs content-negotiation on the Accept HTTP header. It uses Accepts to select a proper format. If the header is not specified or there is no proper format, text/plain is used.

func (*Ctx) Fresh

func (ctx *Ctx) Fresh() bool

Fresh When the response is still “fresh” in the client’s cache true is returned, otherwise false is returned to indicate that the client cache is now stale and the full response should be sent. When a client sends the Cache-Control: no-cache request header to indicate an end-to-end reload request, this module will return false to make handling these requests transparent. https://github.com/jshttp/fresh/blob/10e0471669dbbfbfd8de65bc6efac2ddd0bfa057/index.js#L33

func (*Ctx) Get

func (ctx *Ctx) Get(key string) (value string)

Get returns the HTTP request header specified by field. Field names are case-insensitive Returned value is only valid within the handler. Do not store any references. Make copies or use the Immutable setting instead.

func (*Ctx) Hostname

func (ctx *Ctx) Hostname() string

Hostname contains the hostname derived from the Host HTTP header. Returned value is only valid within the handler. Do not store any references. Make copies or use the Immutable setting instead.

func (*Ctx) IP

func (ctx *Ctx) IP() string

IP returns the remote IP address of the request.

func (*Ctx) IPs

func (ctx *Ctx) IPs() []string

IPs returns an string slice of IP addresses specified in the X-Forwarded-For request header.

func (*Ctx) Is

func (ctx *Ctx) Is(extension string) bool

Is returns the matching content type, if the incoming request’s Content-Type HTTP header field matches the MIME type specified by the type parameter

func (*Ctx) JSON

func (ctx *Ctx) JSON(data interface{}) error

JSON converts any interface or string to JSON using Jsoniter. This method also sets the content header to application/json.

func (*Ctx) JSONP

func (ctx *Ctx) JSONP(data interface{}, callback ...string) error

JSONP sends a JSON response with JSONP support. This method is identical to JSON, except that it opts-in to JSONP callback support. By default, the callback name is simply callback.

func (ctx *Ctx) Links(link ...string)

Links joins the links followed by the property to populate the response’s Link HTTP header field.

func (*Ctx) Locals

func (ctx *Ctx) Locals(key string, value ...interface{}) (val interface{})

Locals makes it possible to pass interface{} values under string keys scoped to the request and therefore available to all following routes that match the request.

func (*Ctx) Location

func (ctx *Ctx) Location(path string)

Location sets the response Location HTTP header to the specified path parameter.

func (*Ctx) Method

func (ctx *Ctx) Method(override ...string) string

Method contains a string corresponding to the HTTP method of the request: GET, POST, PUT and so on.

func (*Ctx) MultipartForm

func (ctx *Ctx) MultipartForm() (*multipart.Form, error)

MultipartForm parse form entries from binary. This returns a map[string][]string, so given a key the value will be a string slice.

func (*Ctx) Next

func (ctx *Ctx) Next(err ...error)

Next executes the next method in the stack that matches the current route. You can pass an optional error for custom error handling.

func (*Ctx) OriginalURL

func (ctx *Ctx) OriginalURL() string

OriginalURL contains the original request URL. Returned value is only valid within the handler. Do not store any references. Make copies or use the Immutable setting instead.

func (*Ctx) Params

func (ctx *Ctx) Params(key string) string

Params is used to get the route parameters. Defaults to empty string "", if the param doesn't exist.

func (*Ctx) Path

func (ctx *Ctx) Path(override ...string) string

Path returns the path part of the request URL. Optionally, you could override the path.

func (*Ctx) Protocol

func (ctx *Ctx) Protocol() string

Protocol contains the request protocol string: http or https for TLS requests.

func (*Ctx) Query

func (ctx *Ctx) Query(key string) (value string)

Query returns the query string parameter in the url. Returned value is only valid within the handler. Do not store any references. Make copies or use the Immutable setting instead.

func (*Ctx) Range

func (ctx *Ctx) Range(size int) (rangeData Range, err error)

Range returns a struct containing the type and a slice of ranges.

func (*Ctx) Redirect

func (ctx *Ctx) Redirect(location string, status ...int)

Redirect to the URL derived from the specified path, with specified status. If status is not specified, status defaults to 302 Found

func (*Ctx) Render

func (ctx *Ctx) Render(name string, bind interface{}) (err error)

Render a template with data and sends a text/html response. We support the following engines: html, amber, handlebars, mustache, pug

func (*Ctx) Route

func (ctx *Ctx) Route() *Route

Route returns the matched Route struct.

func (*Ctx) SaveFile

func (ctx *Ctx) SaveFile(fileheader *multipart.FileHeader, path string) error

SaveFile saves any multipart file to disk.

func (*Ctx) Secure

func (ctx *Ctx) Secure() bool

Secure returns a boolean property, that is true, if a TLS connection is established.

func (*Ctx) Send

func (ctx *Ctx) Send(bodies ...interface{})

Send sets the HTTP response body. The input can be of any type, io.Reader is also supported.

func (*Ctx) SendBytes

func (ctx *Ctx) SendBytes(body []byte)

SendBytes sets the HTTP response body for []byte types This means no type assertion, recommended for faster performance

func (*Ctx) SendFile

func (ctx *Ctx) SendFile(file string, uncompressed ...bool)

SendFile transfers the file from the given path. The file is compressed by default, disable this by passing a 'true' argument Sets the Content-Type response HTTP header field based on the filenames extension.

func (*Ctx) SendStatus

func (ctx *Ctx) SendStatus(status int)

SendStatus sets the HTTP status code and if the response body is empty, it sets the correct status message in the body.

func (*Ctx) SendStream

func (ctx *Ctx) SendStream(stream io.Reader, size ...int)

SendStream sets response body stream and optional body size

func (*Ctx) SendString

func (ctx *Ctx) SendString(body string)

SendString sets the HTTP response body for string types This means no type assertion, recommended for faster performance

func (*Ctx) Set

func (ctx *Ctx) Set(key string, val string)

Set sets the response’s HTTP header field to the specified key, value.

func (*Ctx) Stale

func (ctx *Ctx) Stale() bool

Stale is not implemented yet, pull requests are welcome!

func (*Ctx) Status

func (ctx *Ctx) Status(status int) *Ctx

Status sets the HTTP status for the response. This method is chainable.

func (*Ctx) Subdomains

func (ctx *Ctx) Subdomains(offset ...int) []string

Subdomains returns a string slice of subdomains in the domain name of the request. The subdomain offset, which defaults to 2, is used for determining the beginning of the subdomain segments.

func (*Ctx) Type

func (ctx *Ctx) Type(extension string) *Ctx

Type sets the Content-Type HTTP header to the MIME type specified by the file extension.

func (*Ctx) Vary

func (ctx *Ctx) Vary(fields ...string)

Vary adds the given header field to the Vary response header. This will append the header, if not already listed, otherwise leaves it listed in the current location.

func (*Ctx) Write

func (ctx *Ctx) Write(bodies ...interface{})

Write appends any input to the HTTP body response, io.Reader is also supported as input.

func (*Ctx) XHR

func (ctx *Ctx) XHR() bool

XHR returns a Boolean property, that is true, if the request’s X-Requested-With header field is XMLHttpRequest, indicating that the request was issued by a client library (such as jQuery).

type Group

type Group struct {
	// contains filtered or unexported fields
}

Group struct

func (*Group) Add

func (grp *Group) Add(method, path string, handlers ...Handler) *Route

Add ...

func (*Group) All

func (grp *Group) All(path string, handlers ...Handler) []*Route

All ...

func (*Group) Connect

func (grp *Group) Connect(path string, handlers ...Handler) *Route

Connect ...

func (*Group) Delete

func (grp *Group) Delete(path string, handlers ...Handler) *Route

Delete ...

func (*Group) Get

func (grp *Group) Get(path string, handlers ...Handler) *Route

Get ...

func (*Group) Group

func (grp *Group) Group(prefix string, handlers ...Handler) *Group

Group is used for Routes with common prefix to define a new sub-router with optional middleware.

func (*Group) Head

func (grp *Group) Head(path string, handlers ...Handler) *Route

Head ...

func (*Group) Options

func (grp *Group) Options(path string, handlers ...Handler) *Route

Options ...

func (*Group) Patch

func (grp *Group) Patch(path string, handlers ...Handler) *Route

Patch ...

func (*Group) Post

func (grp *Group) Post(path string, handlers ...Handler) *Route

Post ...

func (*Group) Put

func (grp *Group) Put(path string, handlers ...Handler) *Route

Put ...

func (*Group) Static

func (grp *Group) Static(prefix, root string, config ...Static) *Route

Static ...

func (*Group) Trace

func (grp *Group) Trace(path string, handlers ...Handler) *Route

Trace ...

func (*Group) Use

func (grp *Group) Use(args ...interface{}) *Route

Use registers a middleware route. Middleware matches requests beginning with the provided prefix. Providing a prefix is optional, it defaults to "/".

- group.Use(handler) - group.Use("/api", handler) - group.Use("/api", handler, handler)

type Handler

type Handler = func(*Ctx)

Handler defines a function to serve HTTP requests.

type Map

type Map map[string]interface{}

Map is a shortcut for map[string]interface{}, useful for JSON returns

type Range

type Range struct {
	Type   string
	Ranges []struct {
		Start int
		End   int
	}
}

Range data for ctx.Range

type Route

type Route struct {

	// Public fields
	Path     string    // Original registered route path
	Method   string    // HTTP method
	Handlers []Handler // Ctx handlers
	// contains filtered or unexported fields
}

Route is a struct that holds all metadata for each registered handler

type Settings

type Settings struct {

	// Enables the "Server: value" HTTP header.
	// Default: ""
	ServerHeader string

	// Enable strict routing. When enabled, the router treats "/foo" and "/foo/" as different.
	// By default this is disabled and both "/foo" and "/foo/" will execute the same handler.
	StrictRouting bool

	// Enable case sensitive routing. When enabled, "/FoO" and "/foo" are different routes.
	// By default this is disabled and both "/FoO" and "/foo" will execute the same handler.
	CaseSensitive bool

	// Enables handler values to be immutable even if you return from handler
	// Default: false
	Immutable bool

	// Enable or disable ETag header generation, since both weak and strong etags are generated
	// using the same hashing method (CRC-32). Weak ETags are the default when enabled.
	// Default value false
	ETag bool

	// This will spawn multiple Go processes listening on the same port
	// Default: false
	Prefork bool

	// Max body size that the server accepts
	// Default: 4 * 1024 * 1024
	BodyLimit int

	// Maximum number of concurrent connections.
	// Default: 256 * 1024
	Concurrency int

	// Disable keep-alive connections, the server will close incoming connections after sending the first response to client
	// Default: false
	DisableKeepalive bool

	// When set to true causes the default date header to be excluded from the response.
	// Default: false
	DisableDefaultDate bool

	// When set to true, causes the default Content-Type header to be excluded from the Response.
	// Default: false
	DisableDefaultContentType bool

	// By default all header names are normalized: conteNT-tYPE -> Content-Type
	// Default: false
	DisableHeaderNormalizing bool

	// When set to true, it will not print out the «Fiber» ASCII art and listening address
	// Default: false
	DisableStartupMessage bool

	// Templates is the interface that wraps the Render function.
	// Default: nil
	Templates Templates

	// The amount of time allowed to read the full request including body.
	// Default: unlimited
	ReadTimeout time.Duration

	// The maximum duration before timing out writes of the response.
	// Default: unlimited
	WriteTimeout time.Duration

	// The maximum amount of time to wait for the next request when keep-alive is enabled.
	// Default: unlimited
	IdleTimeout time.Duration
}

Settings holds is a struct holding the server settings

type Static

type Static struct {
	// This works differently than the github.com/gofiber/compression middleware
	// The server tries minimizing CPU usage by caching compressed files.
	// It adds ".fiber.gz" suffix to the original file name.
	// Optional. Default value false
	Compress bool

	// Enables byte range requests if set to true.
	// Optional. Default value false
	ByteRange bool

	// Enable directory browsing.
	// Optional. Default value false.
	Browse bool

	// Index file for serving a directory.
	// Optional. Default value "index.html".
	Index string
}

Static struct

type Templates

type Templates interface {
	Render(io.Writer, string, interface{}) error
}

Templates is the interface that wraps the Render function.

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
f or F : Jump to identifier