Documentation
¶
Index ¶
- Constants
- Variables
- func ReleaseRequest(req *BaseRequest)
- func ReleaseResponse(res *BaseResponse)
- func StatusMessage(statusCode int) string
- type Application
- type ApplicationConfig
- type BaseRequest
- func (req *BaseRequest) Context() context.Context
- func (req *BaseRequest) Cookie(name string) []byte
- func (req *BaseRequest) Data(dst interface{}) error
- func (req *BaseRequest) Header(name string) []byte
- func (req *BaseRequest) Host() []byte
- func (req *BaseRequest) IsJSON() bool
- func (req *BaseRequest) Method() []byte
- func (req *BaseRequest) Param(name string) string
- func (req *BaseRequest) Path() []byte
- func (req *BaseRequest) Post(name string) []byte
- func (req *BaseRequest) PostMulti(name string) [][]byte
- func (req *BaseRequest) Query(name string) []byte
- func (req *BaseRequest) QueryMulti(name string) [][]byte
- func (req *BaseRequest) Raw() *fasthttp.RequestCtx
- func (req *BaseRequest) URI() *fasthttp.URI
- func (req *BaseRequest) WantsJSON() bool
- func (req *BaseRequest) WithContext(ctx context.Context) Request
- type BaseResponse
- func (res *BaseResponse) Cookie(cookie *fasthttp.Cookie) Response
- func (res *BaseResponse) Data(data interface{}) Result
- func (res *BaseResponse) End() Result
- func (res *BaseResponse) Error(err error, options ...interface{}) Result
- func (res *BaseResponse) File(filepath string) Result
- func (res *BaseResponse) FileDownload(filepath, filename string) Result
- func (res *BaseResponse) Header(name, value string) Response
- func (res *BaseResponse) Redirect(uri string, code int) Result
- func (res *BaseResponse) Status(status int) Response
- type FasthttpService
- type FasthttpServiceConfiguration
- type FasthttpServiceConfigurationTLS
- type Handler
- type Middleware
- type QueryString
- type Request
- type Response
- type Result
- type Routable
- type Router
- type RouterConfig
- type Service
- type ServiceConfig
Constants ¶
const ( StatusContinue = 100 // RFC 7231, 6.2.1 StatusSwitchingProtocols = 101 // RFC 7231, 6.2.2 StatusProcessing = 102 // RFC 2518, 10.1 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 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 StatusUnprocessableEntity = 422 // RFC 4918, 11.2 StatusLocked = 423 // RFC 4918, 11.3 StatusFailedDependency = 424 // RFC 4918, 11.4 StatusUpgradeRequired = 426 // RFC 7231, 6.5.15 StatusPreconditionRequired = 428 // RFC 6585, 3 StatusTooManyRequests = 429 // RFC 6585, 4 StatusRequestHeaderFieldsTooLarge = 431 // RFC 6585, 5 StatusInternalServerError = 500 // RFC 7231, 6.6.1 StatusNotImplemented = 501 // RFC 7231, 6.6.2 StatusBadGateway = 502 // RFC 7231, 6.6.3 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 stolen from valyala/fasthttp.
Variables ¶
var ( InternalServerErrorCode = "internal-server-error" InternalServerErrorMessage = "We encountered an internal error or misconfiguration and was unable to complete your request." NotFoundErrorCode = "not-found" NotFoundErrorMessage = "We could not find the resource you requested." MethodNotAllowedErrorCode = "method-not-allowed" MethodNotAllowedErrorMessage = "We believe that the used request method is inappropriate for the resource you requested." )
Functions ¶
func ReleaseRequest ¶ added in v1.3.0
func ReleaseRequest(req *BaseRequest)
func ReleaseResponse ¶ added in v1.3.0
func ReleaseResponse(res *BaseResponse)
func StatusMessage ¶ added in v1.1.0
StatusMessage returns HTTP status message for the given status code.
Types ¶
type Application ¶ added in v1.0.0
type Application struct {
Configuration ApplicationConfig
// contains filtered or unexported fields
}
func NewApplication ¶ added in v1.0.0
func NewApplication(config ApplicationConfig, router Router) *Application
func (*Application) Name ¶ added in v1.0.0
func (app *Application) Name() string
func (*Application) Restart ¶ added in v1.0.0
func (app *Application) Restart() error
func (*Application) Start ¶ added in v1.0.0
func (app *Application) Start() error
func (*Application) Stop ¶ added in v1.0.0
func (app *Application) Stop() error
type ApplicationConfig ¶ added in v1.0.0
type ApplicationConfig struct {
Name string
ServiceStarter rscsrv.ServiceStarter
HTTP FasthttpServiceConfiguration
}
type BaseRequest ¶ added in v1.3.0
type BaseRequest struct {
// contains filtered or unexported fields
}
func AcquireRequest ¶ added in v1.3.0
func AcquireRequest(ctx context.Context, r *fasthttp.RequestCtx) *BaseRequest
func (*BaseRequest) Context ¶ added in v1.3.0
func (req *BaseRequest) Context() context.Context
func (*BaseRequest) Cookie ¶ added in v1.3.0
func (req *BaseRequest) Cookie(name string) []byte
func (*BaseRequest) Data ¶ added in v1.3.0
func (req *BaseRequest) Data(dst interface{}) error
func (*BaseRequest) Header ¶ added in v1.3.0
func (req *BaseRequest) Header(name string) []byte
func (*BaseRequest) Host ¶ added in v1.3.0
func (req *BaseRequest) Host() []byte
func (*BaseRequest) IsJSON ¶ added in v1.3.0
func (req *BaseRequest) IsJSON() bool
func (*BaseRequest) Method ¶ added in v1.3.0
func (req *BaseRequest) Method() []byte
func (*BaseRequest) Param ¶ added in v1.3.0
func (req *BaseRequest) Param(name string) string
func (*BaseRequest) Path ¶ added in v1.3.0
func (req *BaseRequest) Path() []byte
func (*BaseRequest) Post ¶ added in v1.3.0
func (req *BaseRequest) Post(name string) []byte
func (*BaseRequest) PostMulti ¶ added in v1.3.0
func (req *BaseRequest) PostMulti(name string) [][]byte
func (*BaseRequest) Query ¶ added in v1.3.0
func (req *BaseRequest) Query(name string) []byte
func (*BaseRequest) QueryMulti ¶ added in v1.3.0
func (req *BaseRequest) QueryMulti(name string) [][]byte
func (*BaseRequest) Raw ¶ added in v1.3.0
func (req *BaseRequest) Raw() *fasthttp.RequestCtx
func (*BaseRequest) URI ¶ added in v1.3.0
func (req *BaseRequest) URI() *fasthttp.URI
func (*BaseRequest) WantsJSON ¶ added in v1.3.0
func (req *BaseRequest) WantsJSON() bool
func (*BaseRequest) WithContext ¶ added in v1.3.0
func (req *BaseRequest) WithContext(ctx context.Context) Request
type BaseResponse ¶ added in v1.3.0
type BaseResponse struct {
// contains filtered or unexported fields
}
func AcquireResponse ¶ added in v1.3.0
func AcquireResponse(r *fasthttp.RequestCtx) *BaseResponse
func (*BaseResponse) Cookie ¶ added in v1.3.0
func (res *BaseResponse) Cookie(cookie *fasthttp.Cookie) Response
func (*BaseResponse) Data ¶ added in v1.3.0
func (res *BaseResponse) Data(data interface{}) Result
func (*BaseResponse) End ¶ added in v1.3.0
func (res *BaseResponse) End() Result
func (*BaseResponse) Error ¶ added in v1.3.0
func (res *BaseResponse) Error(err error, options ...interface{}) Result
func (*BaseResponse) File ¶ added in v1.3.0
func (res *BaseResponse) File(filepath string) Result
func (*BaseResponse) FileDownload ¶ added in v1.3.0
func (res *BaseResponse) FileDownload(filepath, filename string) Result
func (*BaseResponse) Header ¶ added in v1.3.0
func (res *BaseResponse) Header(name, value string) Response
func (*BaseResponse) Redirect ¶ added in v1.3.0
func (res *BaseResponse) Redirect(uri string, code int) Result
func (*BaseResponse) Status ¶ added in v1.3.0
func (res *BaseResponse) Status(status int) Response
type FasthttpService ¶
type FasthttpService struct {
Configuration FasthttpServiceConfiguration
Server fasthttp.Server
// contains filtered or unexported fields
}
FasthttpService implements the server for starting
func (*FasthttpService) ApplyConfiguration ¶
func (service *FasthttpService) ApplyConfiguration(configuration interface{}) error
ApplyConfiguration checks if the passing interface is a `FasthttpServiceConfiguration` and applies its configuration to the service.
func (*FasthttpService) LoadConfiguration ¶
func (service *FasthttpService) LoadConfiguration() (interface{}, error)
LoadConfiguration does not do anything in this implementation. This methods is just a placeholder to be overwritten on its usage.
func (*FasthttpService) Restart ¶
func (service *FasthttpService) Restart() error
Restart returns an error due to fasthttp not being able to stop the service.
func (*FasthttpService) Start ¶
func (service *FasthttpService) Start() error
Start ListenAndServe the server. This method is blocking because it uses the fasthttp.ListenAndServe implementation.
func (*FasthttpService) Stop ¶
func (service *FasthttpService) Stop() error
Stop closes the listener and waits the `Start` to stop.
type FasthttpServiceConfiguration ¶
type FasthttpServiceConfiguration struct {
Bind string
TLS *FasthttpServiceConfigurationTLS
}
FasthttpServiceConfiguration keeps all the configuration needed to start the `FasthttpService`.
type FasthttpServiceConfigurationTLS ¶ added in v1.1.0
FasthttpServiceConfigurationTLS keeps the configuration for starting a TLS server.
type Middleware ¶
Middleware is an interface for adding middleware to a Router instance
type QueryString ¶ added in v1.1.0
type QueryString interface {
String(string, ...string) string
Int(string, ...int) int
Int64(string, ...int64) int64
Float(string, ...float64) float64
Bool(string, ...bool) bool
}
func ParseQuery ¶ added in v1.1.0
func ParseQuery(req Request) QueryString
type Request ¶ added in v1.0.0
type Request interface {
// Path returns the path of the current URL
Path() []byte
// Method returns the HTTP method
Method() []byte
// IsJSON return weather request body is application/json
IsJSON() bool
// WantsJSON return weather request accepts application/json
WantsJSON() bool
// URI returns the raw URI
URI() *fasthttp.URI
// Header return a header value by name. If the header is not found
// an empty string will be returned.
Header(name string) []byte
// Host returns the host of the request.
Host() []byte
// Param grabs route param by name
Param(name string) string
// Query grabs input from the query string by name
Query(name string) []byte
// QueryMulti grabs multiple input from the query string by name
QueryMulti(name string) [][]byte
// Data unmarshals request body to dst
Data(dst interface{}) error
// Post grabs input from the post data by name
Post(name string) []byte
// PostMulti grabs multiple input from the post data by name
PostMulti(name string) [][]byte
// Cookie grabs input from cookies by name
Cookie(name string) []byte
// Context returns the context.Context of the current request
Context() context.Context
// WithContext returns a shallow copy of the request with a new context
WithContext(ctx context.Context) Request
// Raw returns the fasthttp.RequestCtx of the current request
Raw() *fasthttp.RequestCtx
}
Request is used to retrieve data from an HTTP request
type Response ¶ added in v1.0.0
type Response interface {
// Cookie sets an HTTP cookie on the response
// See also `fasthttp.AcquireCookie`
Cookie(cookie *fasthttp.Cookie) Response
// Status sets the HTTP status code of the response. This can only be called once.
Status(status int) Response
// Header adds an HTTP header to the response
Header(name, value string) Response
// Data responds with data provided
//
// Most types will converted to a string representation except structs,
// arrays and maps which will be serialized to JSON.
Data(data interface{}) Result
// Error sends the default 500 response
Error(error, ...interface{}) Result
File(filepath string) Result
FileDownload(filepath, filename string) Result
// Redirect redirects the client to a URL
Redirect(uri string, code int) Result
// End ends the response chain
End() Result
}
Response is used to send data to the client
type Result ¶ added in v1.0.0
type Result interface {
Data(data interface{}) Result
Error(error) Result
Redirect(uri string, code int) Result
File(filepath string) Result
FileDownload(filepath, filename string) Result
// End release the resources
End()
}
Result is used to finish a request
type Routable ¶
type Routable interface {
Delete(path string, handler Handler)
Get(path string, handler Handler)
Head(path string, handler Handler)
Options(path string, handler Handler)
Patch(path string, handler Handler)
Post(path string, handler Handler)
Put(path string, handler Handler)
Prefix(path string) Routable
Group(func(Routable))
Use(...Middleware)
With(...Middleware) Routable
}
type Router ¶
type Router interface {
Routable
Handler() fasthttp.RequestHandler
}
func DefaultRouter ¶ added in v1.0.0
func DefaultRouter() Router
func NewRouter ¶
func NewRouter(config RouterConfig) Router
type RouterConfig ¶ added in v1.0.0
type ServiceConfig ¶ added in v1.4.0
type ServiceConfig struct {
Name string
Router Router
Bind string
TLS *FasthttpServiceConfigurationTLS
}
ServiceConfig TODO
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
cors
command
|
|
|
errors
command
|
|
|
files
command
|
|
|
helloworld
command
|
|
|
middlewares
command
|
|
|
services
command
|
|
|
todos
command
|
|