Documentation ¶
Index ¶
- Constants
- Variables
- func Mode() string
- func SetMode(mode string)
- type HandlerChain
- type HandlerFunc
- type RequestCtx
- func (c *RequestCtx) Abort()
- func (c *RequestCtx) AddParam(key, value string)
- func (c *RequestCtx) Bind(val interface{}, bindingTypes ...binding.Binding) error
- func (c *RequestCtx) ContentType() string
- func (c *RequestCtx) Copy() *RequestCtx
- func (c *RequestCtx) DeleteCookie(old http.Cookie)
- func (c *RequestCtx) Encode(code int, encoding encoding.Encoding) error
- func (c *RequestCtx) Get(key interface{}) (value interface{}, ok bool)
- func (c *RequestCtx) HandlerName() string
- func (c *RequestCtx) HandlerNames() []string
- func (c *RequestCtx) Next()
- func (c *RequestCtx) Param(key string) []byte
- func (c *RequestCtx) Query(key string) (string, bool)
- func (c *RequestCtx) QueryArray(key string) ([]string, bool)
- func (c *RequestCtx) RawParamKeys() [][]byte
- func (c *RequestCtx) RawParamValues() [][]byte
- func (c *RequestCtx) Redirect(code int, location string) error
- func (c *RequestCtx) RemoteIP() string
- func (c *RequestCtx) SSEvent(evt encoding.SSEvent) error
- func (c *RequestCtx) SendBytes(code int, data []byte, contentType string) error
- func (c *RequestCtx) SendFile(filepath string)
- func (c *RequestCtx) SendFileAttachment(filepath, filename string)
- func (c *RequestCtx) SendFileUsingFS(filepath string, fs http.FileSystem)
- func (c *RequestCtx) SendFromReader(code int, reader io.Reader, contentType string, contentLength int64) error
- func (c *RequestCtx) SendJSON(code int, val interface{}) error
- func (c *RequestCtx) SendString(code int, format string, args ...interface{}) error
- func (c *RequestCtx) Set(key interface{}, val interface{})
- func (c *RequestCtx) SetCookie(cookie *http.Cookie)
- func (c *RequestCtx) SetHeader(key, value string)
- func (c *RequestCtx) SetStatus(code int)
- type ResponseWriter
- type Route
- func (r *Route) All(path string, h HandlerFunc) *Route
- func (r *Route) Connect(path string, h ...HandlerFunc) *Route
- func (r *Route) Delete(path string, h ...HandlerFunc) *Route
- func (r *Route) Get(path string, h ...HandlerFunc) *Route
- func (r *Route) GroupPath(pth string) Route
- func (r *Route) Head(path string, h ...HandlerFunc) *Route
- func (r *Route) Method(method string, relativePath string, handlerFuncs ...HandlerFunc) *Route
- func (r *Route) Options(path string, h ...HandlerFunc) *Route
- func (r *Route) Patch(path string, h ...HandlerFunc) *Route
- func (r *Route) Post(path string, h ...HandlerFunc) *Route
- func (r *Route) Put(path string, h ...HandlerFunc) *Route
- func (r *Route) SetMethodNotAllowedHandler(f ...HandlerFunc)
- func (r *Route) SetNotFoundHandler(f ...HandlerFunc)
- func (r *Route) Trace(path string, h ...HandlerFunc) *Route
- func (r *Route) Use(h ...HandlerFunc)
- type Router
Constants ¶
const ( DebugMode = "debug" ProductionMode = "production" )
The raam mode to run. The Debug Mode will print debugging messages. The Production won't.
const EnvRaamMode = "RAAM_MODE"
EnvRaamMode is the environment variable used to set the raam mode.
Variables ¶
var DefaultErrWriter io.Writer = os.Stderr
DefaultErrWriter is the default error writer. All raam errors will be sent to it.
var DefaultOutWriter io.Writer = os.Stdout
DefaultOutWriter is the default output writer. All raam logs will be sent to it.
Functions ¶
Types ¶
type HandlerChain ¶
type HandlerChain []HandlerFunc
func (HandlerChain) Last ¶
func (c HandlerChain) Last() HandlerFunc
type HandlerFunc ¶
type HandlerFunc func(*RequestCtx)
HandlerFunc is a function that handles HTTP requests.
type RequestCtx ¶
type RequestCtx struct { *http.Request Writer ResponseWriter // contains filtered or unexported fields }
RequestCtx represents a request's context. It's a combination of http.Request, http.ResponseWriter and helpful methods. All functions that handle requests will receive an instance of this type.
func (*RequestCtx) Abort ¶
func (c *RequestCtx) Abort()
func (*RequestCtx) AddParam ¶
func (c *RequestCtx) AddParam(key, value string)
AddParam adds a parameter to the context (or replaces the current one). This is mostly useful for e2e testing.
func (*RequestCtx) Bind ¶
func (c *RequestCtx) Bind(val interface{}, bindingTypes ...binding.Binding) error
Bind binds a value into the specific interface. It either uses the default binding type or loops through binding values provided until it finds a suitable one.
func (*RequestCtx) ContentType ¶
func (c *RequestCtx) ContentType() string
ContentType gets the Content-Type header from the request.
func (*RequestCtx) Copy ¶
func (c *RequestCtx) Copy() *RequestCtx
Copy returns a copy of the RequestCtx, which can be safely used out of the request's scope.
func (*RequestCtx) DeleteCookie ¶
func (c *RequestCtx) DeleteCookie(old http.Cookie)
DeleteCookie adds a Set-Cookie header with that domain, path and name with an empty value, and an expiration date in the past. This follows RFC 6265, section 3.1 (https://tools.ietf.org/search/rfc6265)
func (*RequestCtx) Encode ¶
func (c *RequestCtx) Encode(code int, encoding encoding.Encoding) error
Encode encodes some data into the response body. This method can be used to implement custom encoding. Furthermore a few of the provided encoding methods do not have their own methods (ex. MsgPack and ProtoBuf) because we do not want to overwhelm users with a crazy amount of methods.
func (*RequestCtx) Get ¶
func (c *RequestCtx) Get(key interface{}) (value interface{}, ok bool)
Get returns the value for the given key, and whether it was found.
func (*RequestCtx) HandlerName ¶
func (c *RequestCtx) HandlerName() string
HandlerName returns the name of the function that handles the request.
func (*RequestCtx) HandlerNames ¶
func (c *RequestCtx) HandlerNames() []string
func (*RequestCtx) Next ¶
func (c *RequestCtx) Next()
Next calls the next handler in the chain. The handler can be either a middleware or the main handler function.
func (*RequestCtx) Param ¶
func (c *RequestCtx) Param(key string) []byte
Param returns a matched request parameter based on its key. It returns a []byte which is the request parameter value. It returns an empty array if nothing was found.
func (*RequestCtx) Query ¶
func (c *RequestCtx) Query(key string) (string, bool)
Query returns the keyed url query value and whether or not it exists.
func (*RequestCtx) QueryArray ¶
func (c *RequestCtx) QueryArray(key string) ([]string, bool)
QueryArray returns the keyed url query values and whether or not they existed.
func (*RequestCtx) RawParamKeys ¶
func (c *RequestCtx) RawParamKeys() [][]byte
RawParamKeys returns the raw request parameter keys.
func (*RequestCtx) RawParamValues ¶
func (c *RequestCtx) RawParamValues() [][]byte
RawParamValues returns the raw request parameter values.
func (*RequestCtx) Redirect ¶
func (c *RequestCtx) Redirect(code int, location string) error
Redirect redirects the request to the specified location.
func (*RequestCtx) RemoteIP ¶
func (c *RequestCtx) RemoteIP() string
RemoteIP parses the IP from the request's remote address and returns the host (without the port).
func (*RequestCtx) SSEvent ¶
func (c *RequestCtx) SSEvent(evt encoding.SSEvent) error
TODO: Implement
func (*RequestCtx) SendBytes ¶
func (c *RequestCtx) SendBytes(code int, data []byte, contentType string) error
SendBytes writes the specified bytes to the response body and sets the Content-Type header to the content type specified. If the content type is empty, the content type is set to application/octet-stream.
func (*RequestCtx) SendFile ¶
func (c *RequestCtx) SendFile(filepath string)
SendFile sends a file to the client.
func (*RequestCtx) SendFileAttachment ¶
func (c *RequestCtx) SendFileAttachment(filepath, filename string)
SendFileAttachment sends a file to the client as an attachment. The filepath should contain the full file path. The filename is only utilized as the default filename for an eventual "Save As" dialog.
func (*RequestCtx) SendFileUsingFS ¶
func (c *RequestCtx) SendFileUsingFS(filepath string, fs http.FileSystem)
SendFileUsingFs utilizesd a file system to send a file to the client.
func (*RequestCtx) SendFromReader ¶
func (c *RequestCtx) SendFromReader(code int, reader io.Reader, contentType string, contentLength int64) error
SendFromReader streams data from the reader into the response body. If the content's length is greater than or equal to 0, the Content-Length header is set to the content length. If the content type is empty, the content type is set to application/octet-stream.
func (*RequestCtx) SendJSON ¶
func (c *RequestCtx) SendJSON(code int, val interface{}) error
SendJSON serializes the specified object as json and writes it to the response body. It also sets the Content-Type header to application/json.
func (*RequestCtx) SendString ¶
func (c *RequestCtx) SendString(code int, format string, args ...interface{}) error
SendString formats a string and writes it to the response body. It also sets the content type to text/plain.
func (*RequestCtx) Set ¶
func (c *RequestCtx) Set(key interface{}, val interface{})
Set is used to store a key/value pair in this context.
func (*RequestCtx) SetCookie ¶
func (c *RequestCtx) SetCookie(cookie *http.Cookie)
SetCookie adds a Set-Cookie header to the response's headers.
func (*RequestCtx) SetHeader ¶
func (c *RequestCtx) SetHeader(key, value string)
SetHeader is a shortcut for c.Writer.Header().Set(key, value). It writes a header in the response. If the value is empty, the method removes the header.
func (*RequestCtx) SetStatus ¶
func (c *RequestCtx) SetStatus(code int)
SetStatus sets the HTTP response status code.
type ResponseWriter ¶
type ResponseWriter interface { http.ResponseWriter http.Hijacker http.Flusher // Returns the HTTP response status code of the current request. Status() int // Returns the number of bytes already written into the response http body. Size() int // Returns true if the response body was already written. Written() bool // Forces to write the http header (which consists of status code + headers). WriteHeaderNow() // get the http.Pusher for server push Pusher() http.Pusher }
ResponseWriter is an interface for responding to HTTP requests.
type Route ¶
type Route struct {
// contains filtered or unexported fields
}
Route represents a single route. This is the main struct, used to register endpoints, middlewares and more.
func (*Route) All ¶
func (r *Route) All(path string, h HandlerFunc) *Route
All registers a new route that handles all requests of any method at path path (relative to the route's path). It returns the route back so that you can chain handlers.
func (*Route) Connect ¶
func (r *Route) Connect(path string, h ...HandlerFunc) *Route
Connect registers a new route that handles all requests of method CONNECT at path path (relative to the route's path). It returns the route back so that you can chain handlers.
func (*Route) Delete ¶
func (r *Route) Delete(path string, h ...HandlerFunc) *Route
Delete registers a new route that handles all requests of method DELETE at path path (relative to the route's path). It returns the route back so that you can chain handlers.
func (*Route) Get ¶
func (r *Route) Get(path string, h ...HandlerFunc) *Route
Get registers a new route that handles all requests of method GET at path path (relative to the route's path). It returns the route back so that you can chain handlers.
func (*Route) Head ¶
func (r *Route) Head(path string, h ...HandlerFunc) *Route
Head registers a new route that handles all requests of method HEAD at path path (relative to the route's path). It returns the route back so that you can chain handlers.
func (*Route) Method ¶
func (r *Route) Method(method string, relativePath string, handlerFuncs ...HandlerFunc) *Route
Method registers a new route that handles all requests of method method at path path (relative to the route's path). It returns the route back so that you can chain handlers.
func (*Route) Options ¶
func (r *Route) Options(path string, h ...HandlerFunc) *Route
Options registers a new route that handles all requests of method OPTIONS at path path (relative to the route's path). It returns the route back so that you can chain handlers.
func (*Route) Patch ¶
func (r *Route) Patch(path string, h ...HandlerFunc) *Route
Patch registers a new route that handles all requests of method PATCH at path path (relative to the route's path). It returns the route back so that you can chain handlers.
func (*Route) Put ¶
func (r *Route) Put(path string, h ...HandlerFunc) *Route
Put registers a new route that handles all requests of method PUT at path path (relative to the route's path). It returns the route back so that you can chain handlers.
func (*Route) SetMethodNotAllowedHandler ¶
func (r *Route) SetMethodNotAllowedHandler(f ...HandlerFunc)
func (*Route) SetNotFoundHandler ¶
func (r *Route) SetNotFoundHandler(f ...HandlerFunc)
func (*Route) Trace ¶
func (r *Route) Trace(path string, h ...HandlerFunc) *Route
Trace registers a new route that handles all requests of method TRACE at path path (relative to the route's path). It returns an Endpoint object that can be used to further configure the endpoint.
func (*Route) Use ¶
func (r *Route) Use(h ...HandlerFunc)
Use registers a new middleware function that is ran when s
type Router ¶
type Router struct { Route // IgnoreTrailingSlash is a configuration option that // determines whether if a route ending with a slash was not found, // an alternative route without the ending slash should be searched. IgnoreTrailingSlash bool // Validators represents list of validators which will run to check for object validity when binding request data into go objects. Validators []binding.Validator }
Router is a struct which handles everything related to multiplexing.
Directories ¶
Path | Synopsis |
---|---|
Package binding is used to bind request data into go objects.
|
Package binding is used to bind request data into go objects. |
Package encoding is used to encode go objects using encoding types.
|
Package encoding is used to encode go objects using encoding types. |
internal
|
|
json
Package json is used to use json encoding methods from different libraries (depending on the commandline arguments).
|
Package json is used to use json encoding methods from different libraries (depending on the commandline arguments). |