Documentation ¶
Index ¶
- Variables
- func AddBinder(ContentType string, Binder func([]byte, interface{}) error)
- func AddTransformer(typeOf reflect.Type, transformer Transformer)
- func DELETE(function interface{}, middleware ...interface{})
- func GET(function interface{}, middleware ...interface{})
- func Methods(Route string) []string
- func PATCH(function interface{}, middleware ...interface{})
- func POST(function interface{}, middleware ...interface{})
- func PUT(function interface{}, middleware ...interface{})
- func Root(Folder string)
- func SetCORSRules(rules *CORSRules)
- func Start(Addr string)
- type CORSRules
- type ErrorHandlerFunc
- type FunctionCall
- type Request
- type RequestHeaders
- type Response
- func HTML(HTMLContent string, StatusCode int) (*Response, error)
- func JSON(content interface{}, StatusCode int) (*Response, error)
- func NoContent() (*Response, error)
- func Text(Text string, StatusCode int) (*Response, error)
- func WebSocket(handler func(conn *websocket.Conn) error) (*Response, error)
- func XML(content interface{}, StatusCode int) (*Response, error)
- type Transformer
Constants ¶
This section is empty.
Variables ¶
var ErrMiddlewareArgTypeMismatch = errors.New("middleware argument mismatches the type signature in the handler")
ErrMiddlewareArgTypeMismatch is thrown when a middleware argument mismatches the type signature in the handler.
var ErrNoTransformer = errors.New("there is no transformer for the argument type specified")
ErrNoTransformer is thrown when there is no transformer for the argument type.
var ErrNotFound = errors.New("route not found")
ErrNotFound is the error sent when the router cannot find a page.
var ErrTooManyArguments = errors.New("the function signature has too many request arguments")
ErrTooManyArguments is thrown when the function signature has too many request arguments.
var ErrTooManyMiddlewareArguments = errors.New("too many arguments for the function signature")
ErrTooManyMiddlewareArguments is thrown when middleware generates too many arguments for the function signature.
var ErrUnknownContentType = errors.New("rainbows doesn't know how to handle the content type specified by the client")
ErrUnknownContentType is thrown when Rainbows doesn't know how to handle the content type specified by the client.
Functions ¶
func AddBinder ¶
AddBinder allows you to set a binder for a request with a custom content type. A blank content type will mean that this will be the default binder if the user does not specify the content type.
func AddTransformer ¶
func AddTransformer(typeOf reflect.Type, transformer Transformer)
AddTransformer is used to add a transformer into Rainbows.
func DELETE ¶
func DELETE(function interface{}, middleware ...interface{})
DELETE is used to register a HTTP DELETE route.
func GET ¶
func GET(function interface{}, middleware ...interface{})
GET is used to register a HTTP GET route.
func PATCH ¶
func PATCH(function interface{}, middleware ...interface{})
PATCH is used to register a HTTP PATCH route.
func POST ¶
func POST(function interface{}, middleware ...interface{})
POST is used to register a HTTP POST route.
func PUT ¶
func PUT(function interface{}, middleware ...interface{})
PUT is used to register a HTTP PUT route.
func SetCORSRules ¶
func SetCORSRules(rules *CORSRules)
SetCORSRules is used to configure CORS rules for a specific path.
Types ¶
type CORSRules ¶
type CORSRules struct {
// Defines which routes are CORS.
GET, POST, PUT, DELETE bool
// Defines the origin which can be used.
OriginRoute string
}
CORSRules are used to define the CORS rules.
type ErrorHandlerFunc ¶
ErrorHandlerFunc is the function signature used to handle errors.
var ErrorHandler ErrorHandlerFunc = func(req Request, err error) *Response { if err == ErrNotFound { r, _ := Text("Route not found.", 404) return r } _ = fmt.Errorf("❌ %s", err) r, _ := Text("Internal Server Error", 500) return r }
ErrorHandler is the function which is called on error.
type FunctionCall ¶
type FunctionCall struct {
// contains filtered or unexported fields
}
FunctionCall is used to call the route function.
func (*FunctionCall) Run ¶
func (f *FunctionCall) Run(additionalArgs ...interface{}) (*Response, error)
Run is used to perform the function call with the additional args specified prepended to the handler.
type Request ¶
type Request interface { // Headers is used to get a interface which can be used to manage the request headers. Headers() RequestHeaders // Bind is used to bind the request body to the interface specified. Bind(iface interface{}) error // Path is used to get the raw path. Path() []byte }
Request is used to define a request manager.
type RequestHeaders ¶
type RequestHeaders interface { // Get is used to get a requests headers as bytes. // Note that the bytes should not be used after the request is done. Get(Key string) []byte // GetString is used to get a requests headers as a string. GetString(Key string) string // Set is used to set the headers in the request. Note this does not edit the response. // This is mainly designed to be used in middleware. Set(Key, Value string) // Keys is used to get the keys of headers. Keys() []string }
RequestHeaders is used to define a manager for request headers.
type Response ¶
type Response struct { // WebsocketHandler is defined if the result is a WebSocket. WebsocketHandler func(*websocket.Conn) error // StatusCode is used to define the status code which should be sent back. StatusCode int // Reader is used to define the reader which should be sent back. Reader io.ReadCloser // Headers are the headers which should be sent back with the response. Headers map[string][]byte }
Response is the response type which is sent back.
type Transformer ¶
Transformer is used to define a type used to transform a param argument.