Documentation ¶
Index ¶
- Constants
- func IsDebugging() bool
- func SetMode(value string)
- type Context
- func (c *Context) BindJSON(obj interface{}) error
- func (c *Context) BindText(obj interface{}) error
- func (c *Context) BindTopic(obj interface{}) error
- func (c *Context) Data(data []byte)
- func (c *Context) GetRawData() []byte
- func (c *Context) GetRawString() string
- func (c *Context) JSON(t interface{})
- func (c *Context) Param(key string) string
- func (c *Context) ShouldBindJSON(obj interface{}) error
- func (c *Context) ShouldBindText(obj interface{}) error
- func (c *Context) ShouldBindTopic(obj interface{}) error
- func (c *Context) String(format string, values ...interface{})
- type Engine
- type RouterGroup
Constants ¶
const ( DebugMode = "debug" ReleaseMode = "release" )
Variables ¶
This section is empty.
Functions ¶
func IsDebugging ¶
func IsDebugging() bool
IsDebugging returns true if the framework is running in debug mode. Use SetMode(mqrr.ReleaseMode) to disable debug mode.
Types ¶
type Context ¶
type Context struct { Request *paho.Publish Params map[string][]string // contains filtered or unexported fields }
Context is a data container. It allows us to pass variables across different procedures, bind request data, validate struct and render response.
func (*Context) BindJSON ¶
BindJSON deserializes the request payload and binds the passed struct pointer. e.g. `json:"var1"`.
func (*Context) BindText ¶
BindText slices the request string into all substrings separated by given separator, then binds the passed struct pointer according to the given slice index. e.g. `text:"2,-"`, `text:"0"`.
func (*Context) BindTopic ¶
BindTopic binds the passed struct pointer using the topic parameters. e.g. `topic:"var1"`.
func (*Context) GetRawData ¶
GetRawData return raw payload data.
func (*Context) GetRawString ¶
GetRawString return raw payload data as string.
func (*Context) JSON ¶
func (c *Context) JSON(t interface{})
JSON serializes the given struct as JSON into the response data.
func (*Context) ShouldBindJSON ¶
ShouldBindJSON is a combiner of BindJSON and binder.Validate.
func (*Context) ShouldBindText ¶
ShouldBindText is a combiner of BindText and binder.Validate.
func (*Context) ShouldBindTopic ¶
ShouldBindTopic is a combiner of BindTopic and binder.Validate.
type Engine ¶
type Engine struct { RouterGroup BaseTopic string // contains filtered or unexported fields }
Engine is the server instance, it contains the connection manager, router and subscriptions. Create an instance of Engine, by using New().
func (*Engine) Route ¶
Route registers a request handler with the given topic. A topic contains multiple levels, each level is separated by a forward slash. A level can be a name, or wildcards like `+` and `#`, or a named variable starts with `:` and `*`.
func (*Engine) RunCfg ¶
func (engine *Engine) RunCfg(cc autopaho.ClientConfig)
RunCfg connects to the MQTT broker using the given client config, then starts listening requests.
type RouterGroup ¶
type RouterGroup struct {
// contains filtered or unexported fields
}
RouterGroup is associated with a topic prefix. In the Route call, it joins all the topic levels to form a full topic.
func (*RouterGroup) Group ¶
func (g *RouterGroup) Group(base string) *RouterGroup
Group creates a new router group with the given topic prefix.
func (*RouterGroup) Route ¶
func (g *RouterGroup) Route(topic string, handler func(c *Context))
Route registers a request handler with the given topic. See Engine.Route for detail.