Documentation ¶
Index ¶
- Constants
- func DefaultErrorEncoder(c pmqtt.Client, topic string, err error)
- func DefaultRequestDecoder(data []byte, v interface{}) error
- func DefaultResponseEncoder(c pmqtt.Client, topic string, v interface{}) error
- type Context
- type DecodeRequestFunc
- type EncodeErrorFunc
- type EncodeResponseFunc
- type HandlerFunc
- type MQTTSubscribe
- type Router
- type Server
- type ServerOption
- func AutoReconnect(autoReconnect bool) ServerOption
- func Broker(broker string) ServerOption
- func CleanSession(cleanSession bool) ServerOption
- func ClientId(clientId string) ServerOption
- func ConnectTimeout(timeout time.Duration) ServerOption
- func ConnectionLostHandler(connectLostHandler pmqtt.ConnectionLostHandler) ServerOption
- func DisconnectQuiesce(quiesce uint) ServerOption
- func ErrorEncoder(en EncodeErrorFunc) ServerOption
- func Logger(logger log.Logger) ServerOption
- func Middleware(m ...middleware.Middleware) ServerOption
- func OnConnectHandler(onConnectHandler pmqtt.OnConnectHandler) ServerOption
- func OrderMatters(orderMatters bool) ServerOption
- func Password(password string) ServerOption
- func PingTimeout(timeout time.Duration) ServerOption
- func RequestDecoder(dec DecodeRequestFunc) ServerOption
- func ResponseEncoder(en EncodeResponseFunc) ServerOption
- func ResumeSubs(resumeSubs bool) ServerOption
- func Username(username string) ServerOption
Constants ¶
const ( ServerTopicPrefix = "/sys" DeviceTopicPrefix = "/device" )
const SupportPackageIsVersion1 = true
SupportPackageIsVersion1 These constants should not be referenced from any other code.
Variables ¶
This section is empty.
Functions ¶
func DefaultErrorEncoder ¶
DefaultErrorEncoder encodes the error to the mqtt response.
func DefaultRequestDecoder ¶
DefaultRequestDecoder decodes the request body to object.
Types ¶
type Context ¶
type Context interface { context.Context Client() pmqtt.Client Message() pmqtt.Message Reset(context.Context, pmqtt.Client, pmqtt.Message, *mux.Params) Middleware(middleware.Handler) middleware.Handler Bind(v interface{}) error BindVars(v interface{}) error Reply(v interface{}) error ReplyErr(err error) }
Context is an MQTT Context.
type DecodeRequestFunc ¶
DecodeRequestFunc is decode request func.
type EncodeErrorFunc ¶
EncodeErrorFunc is encode error func.
type EncodeResponseFunc ¶
EncodeResponseFunc is encode response func.
type HandlerFunc ¶
type HandlerFunc func(Context)
HandlerFunc defines a function to serve MQTT requests.
type MQTTSubscribe ¶
type MQTTSubscribe struct {
// contains filtered or unexported fields
}
func (*MQTTSubscribe) SetServer ¶
func (m *MQTTSubscribe) SetServer(srv *Server)
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router is an MQTT router.
func (*Router) Handle ¶
func (r *Router) Handle(topic string, h HandlerFunc)
Handle registers a new route with a matcher for the Topic.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func NewServer ¶
func NewServer(opts ...ServerOption) *Server
NewServer creates an MQTT server by options.
type ServerOption ¶
type ServerOption func(*Server)
ServerOption is an MQTT server option.
func AutoReconnect ¶
func AutoReconnect(autoReconnect bool) ServerOption
AutoReconnect with mqtt client autoReconnect.
func CleanSession ¶
func CleanSession(cleanSession bool) ServerOption
CleanSession with mqtt client cleanSession.
func ConnectTimeout ¶
func ConnectTimeout(timeout time.Duration) ServerOption
ConnecTimeout with mqtt client connecTimeout.
func ConnectionLostHandler ¶
func ConnectionLostHandler(connectLostHandler pmqtt.ConnectionLostHandler) ServerOption
ConnectionLostHandler with mqtt client connectLostHandler.
func DisconnectQuiesce ¶
func DisconnectQuiesce(quiesce uint) ServerOption
DisconnectQuiesce with mqtt client disconnectQuiesce.
func ErrorEncoder ¶
func ErrorEncoder(en EncodeErrorFunc) ServerOption
ErrorEncoder with error encoder.
func Middleware ¶
func Middleware(m ...middleware.Middleware) ServerOption
Middleware with service middleware option.
func OnConnectHandler ¶
func OnConnectHandler(onConnectHandler pmqtt.OnConnectHandler) ServerOption
OnConnectHandler with mqtt client onConnectHandler.
func OrderMatters ¶
func OrderMatters(orderMatters bool) ServerOption
orderMatters with mqtt client orderMatters.
func PingTimeout ¶
func PingTimeout(timeout time.Duration) ServerOption
PingTimeout with mqtt client pingTimeout.
func RequestDecoder ¶
func RequestDecoder(dec DecodeRequestFunc) ServerOption
RequestDecoder with request decoder.
func ResponseEncoder ¶
func ResponseEncoder(en EncodeResponseFunc) ServerOption
ResponseEncoder with response encoder.
func ResumeSubs ¶
func ResumeSubs(resumeSubs bool) ServerOption
ResumeSubs with mqtt client resumeSubs.