Documentation
¶
Index ¶
- Constants
- func ClientFromContext(ctx context.Context) mqtt.Client
- func ClientFromServerContext(ctx context.Context) (*mqtt.Client, bool)
- func DefaultErrorEncoder(w http.ResponseWriter, r *http.Request, err error)
- func DefaultRequestDecoder(r *http.Request, v interface{}) error
- func DefaultRequestEncoder(_ context.Context, contentType string, in interface{}) ([]byte, error)
- func DefaultRequestVars(r *http.Request, v interface{}) error
- func DefaultResponseEncoder(w http.ResponseWriter, r *http.Request, v interface{}) error
- func MessageFromContext(ctx context.Context) mqtt.Message
- func MessageFromServerContext(ctx context.Context) (*mqtt.Message, bool)
- func RequestFromServerContext(ctx context.Context) (*http.Request, bool)
- func SetOperation(ctx context.Context, op string)
- func WithClient(ctx context.Context, client mqtt.Client) context.Context
- func WithMessage(ctx context.Context, msg mqtt.Message) context.Context
- type CallOption
- type Client
- type ClientOption
- type ContentTypeCallOption
- type Context
- type EmptyCallOption
- type EncodeRequestFunc
- type HandlerFunc
- type HeaderCallOption
- type MQTTResponseWriter
- type OperationCallOption
- type PathTemplateCallOption
- type PublishMQTTFn
- type RouteInfo
- type Router
- type Server
- func (s *Server) Endpoint() (*url.URL, error)
- func (s *Server) MQTTClient() mqtt.Client
- func (s *Server) MQTTHandler() mqtt.MessageHandler
- func (s *Server) MakePublishMQTTFn(timeout time.Duration) PublishMQTTFn
- func (s *Server) MakeSubscribeMQTTFn() SubscribeMQTTFn
- func (s *Server) Route(prefix string, filters ...xhttp.FilterFunc) *Router
- func (s *Server) ServeHTTP(res http.ResponseWriter, req *http.Request)
- func (s *Server) Shutdown(ctx context.Context) error
- func (s *Server) Start(ctx context.Context) error
- func (s *Server) Stop(ctx context.Context) error
- func (s *Server) Use(selector string, m ...middleware.Middleware)
- func (s *Server) WalkHandle(handle func(method, path string, handler http.HandlerFunc)) error
- func (s *Server) WalkRoute(fn WalkRouteFunc) error
- type ServerOption
- func ErrorEncoder(en xhttp.EncodeErrorFunc) ServerOption
- func Filter(filters ...xhttp.FilterFunc) ServerOption
- func MethodNotAllowedHandler(handler http.Handler) ServerOption
- func Middleware(m ...middleware.Middleware) ServerOption
- func NotFoundHandler(handler http.Handler) ServerOption
- func RequestDecoder(dec xhttp.DecodeRequestFunc) ServerOption
- func RequestVarsDecoder(dec xhttp.DecodeRequestFunc) ServerOption
- func ResponseEncoder(en xhttp.EncodeResponseFunc) ServerOption
- func StrictSlash(strictSlash bool) ServerOption
- func Timeout(timeout time.Duration) ServerOption
- func WithClientOption(option *mqtt.ClientOptions) ServerOption
- func WithMustStart(mustStart bool) ServerOption
- type SubscribeMQTTFn
- type Transport
- func (tr *Transport) Client() *mqtt.Client
- func (tr *Transport) Endpoint() string
- func (tr *Transport) Kind() transport.Kind
- func (tr *Transport) Message() *mqtt.Message
- func (tr *Transport) Operation() string
- func (tr *Transport) ReplyHeader() transport.Header
- func (tr *Transport) Request() *http.Request
- func (tr *Transport) RequestHeader() transport.Header
- type Transporter
- type WalkRouteFunc
Constants ¶
const ( MQTT_REPLY_QOS_HEADER = "X-MQTT-Reply-QoS" MQTT_REPLY_RETAIN_HEADER = "X-MQTT-Reply-Retain" MQTT_REPLY_TOPIC_HEADER = "X-MQTT-Reply-Topic" )
Variables ¶
This section is empty.
Functions ¶
func ClientFromServerContext ¶
ClientFromServerContext returns client from context.
func DefaultErrorEncoder ¶
func DefaultErrorEncoder(w http.ResponseWriter, r *http.Request, err error)
DefaultErrorEncoder encodes the error to the HTTP response.
func DefaultRequestDecoder ¶
func DefaultRequestEncoder ¶
DefaultRequestEncoder is an MQTT request encoder.
func DefaultRequestVars ¶
func DefaultResponseEncoder ¶
func DefaultResponseEncoder(w http.ResponseWriter, r *http.Request, v interface{}) error
func MessageFromServerContext ¶
MessageFromServerContext returns message from context.
func RequestFromServerContext ¶
RequestFromServerContext returns request from context.
func SetOperation ¶
SetOperation sets the transport operation.
Types ¶
type CallOption ¶
type CallOption interface {
// contains filtered or unexported methods
}
CallOption configures a Call before it starts or extracts information from a Call after it completes.
func ContentType ¶
func ContentType(contentType string) CallOption
ContentType with request content type.
func Header ¶
func Header(header *http.Header) CallOption
Header returns a CallOptions that retrieves the http response header from server reply.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is an MQTT client.
type ClientOption ¶
type ClientOption func(*clientOptions)
ClientOption is MQTT client option.
func WithMiddleware ¶
func WithMiddleware(m ...middleware.Middleware) ClientOption
WithMiddleware with client middleware.
func WithPublishMQTTFn ¶
func WithPublishMQTTFn(fn PublishMQTTFn) ClientOption
func WithRequestEncoder ¶
func WithRequestEncoder(encoder EncodeRequestFunc) ClientOption
WithRequestEncoder with client request encoder.
func WithTimeout ¶
func WithTimeout(d time.Duration) ClientOption
WithTimeout with client request timeout.
type ContentTypeCallOption ¶
type ContentTypeCallOption struct { EmptyCallOption ContentType string }
ContentTypeCallOption is BodyCallOption
type Context ¶
type Context interface { context.Context Vars() url.Values Client() mqtt.Client Message() mqtt.Message Response() http.ResponseWriter Middleware(middleware.Handler) middleware.Handler Bind(interface{}) error BindVars(interface{}) error JSON(interface{}) error String(string) error Stream(string, io.Reader) error Reset(http.ResponseWriter, *http.Request) }
Context is an MQTT Context.
type EmptyCallOption ¶
type EmptyCallOption struct{}
EmptyCallOption does not alter the Call configuration. It can be embedded in another structure to carry satellite data for use by interceptors.
type EncodeRequestFunc ¶
type EncodeRequestFunc func(ctx context.Context, contentType string, in interface{}) (body []byte, err error)
EncodeRequestFunc is request encode func.
type HandlerFunc ¶
HandlerFunc defines a function to serve MQTT requests.
type HeaderCallOption ¶
type HeaderCallOption struct { EmptyCallOption // contains filtered or unexported fields }
HeaderCallOption is retrieve response header for client call
type MQTTResponseWriter ¶
type MQTTResponseWriter struct {
// contains filtered or unexported fields
}
func (*MQTTResponseWriter) Header ¶
func (rw *MQTTResponseWriter) Header() http.Header
func (*MQTTResponseWriter) WriteHeader ¶
func (rw *MQTTResponseWriter) WriteHeader(statusCode int)
type OperationCallOption ¶
type OperationCallOption struct { EmptyCallOption Operation string }
OperationCallOption is set ServiceMethod for client call
type PathTemplateCallOption ¶
type PathTemplateCallOption struct { EmptyCallOption Pattern string }
PathTemplateCallOption is set path template for client call
type PublishMQTTFn ¶
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router is an MQTT router.
func (*Router) Group ¶
func (r *Router) Group(prefix string, filters ...xhttp.FilterFunc) *Router
Group returns a new router group.
func (*Router) Handle ¶
func (r *Router) Handle(method, relativePath string, h HandlerFunc, filters ...xhttp.FilterFunc)
Handle registers a new route with a matcher for the URL path and method.
func (*Router) POST ¶
func (r *Router) POST(path string, h HandlerFunc, m ...xhttp.FilterFunc)
POST registers a new POST route for a path with matching handler in the router.
type Server ¶
Server is an MQTT Topic Route server wrapper.
func NewServer ¶
func NewServer(opts ...ServerOption) *Server
NewServer creates an MQTT server by options.
func (*Server) MQTTClient ¶
func (*Server) MQTTHandler ¶
func (s *Server) MQTTHandler() mqtt.MessageHandler
func (*Server) MakePublishMQTTFn ¶
func (s *Server) MakePublishMQTTFn(timeout time.Duration) PublishMQTTFn
func (*Server) MakeSubscribeMQTTFn ¶
func (s *Server) MakeSubscribeMQTTFn() SubscribeMQTTFn
func (*Server) Route ¶
func (s *Server) Route(prefix string, filters ...xhttp.FilterFunc) *Router
Route registers an MQTT router.
func (*Server) ServeHTTP ¶
func (s *Server) ServeHTTP(res http.ResponseWriter, req *http.Request)
ServeMQTT should write reply headers and data to the ResponseWriter and then return.
func (*Server) Use ¶
func (s *Server) Use(selector string, m ...middleware.Middleware)
Use uses a service middleware with selector. selector:
- '/*'
- '/helloworld.v1.Greeter/*'
- '/helloworld.v1.Greeter/SayHello'
func (*Server) WalkHandle ¶
func (s *Server) WalkHandle(handle func(method, path string, handler http.HandlerFunc)) error
WalkHandle walks the router and all its sub-routers, calling walkFn for each route in the tree.
func (*Server) WalkRoute ¶
func (s *Server) WalkRoute(fn WalkRouteFunc) error
WalkRoute walks the router and all its sub-routers, calling walkFn for each route in the tree.
type ServerOption ¶
type ServerOption func(*Server)
ServerOption is an MQTT server option.
func ErrorEncoder ¶
func ErrorEncoder(en xhttp.EncodeErrorFunc) ServerOption
ErrorEncoder with error encoder.
func Filter ¶
func Filter(filters ...xhttp.FilterFunc) ServerOption
Filter with MQTT middleware option.
func MethodNotAllowedHandler ¶
func MethodNotAllowedHandler(handler http.Handler) ServerOption
func Middleware ¶
func Middleware(m ...middleware.Middleware) ServerOption
Middleware with service middleware option.
func NotFoundHandler ¶
func NotFoundHandler(handler http.Handler) ServerOption
func RequestDecoder ¶
func RequestDecoder(dec xhttp.DecodeRequestFunc) ServerOption
RequestDecoder with request decoder.
func RequestVarsDecoder ¶
func RequestVarsDecoder(dec xhttp.DecodeRequestFunc) ServerOption
RequestVarsDecoder with request decoder.
func ResponseEncoder ¶
func ResponseEncoder(en xhttp.EncodeResponseFunc) ServerOption
ResponseEncoder with response encoder.
func StrictSlash ¶
func StrictSlash(strictSlash bool) ServerOption
StrictSlash is with mux's StrictSlash If true, when the path pattern is "/path/", accessing "/path" will redirect to the former and vice versa.
func WithClientOption ¶
func WithClientOption(option *mqtt.ClientOptions) ServerOption
func WithMustStart ¶
func WithMustStart(mustStart bool) ServerOption
type SubscribeMQTTFn ¶
type Transport ¶
type Transport struct {
// contains filtered or unexported fields
}
Transport is an MQTT transport.
func (*Transport) ReplyHeader ¶
ReplyHeader returns the reply header.
func (*Transport) RequestHeader ¶
RequestHeader returns the request header.
type Transporter ¶
type Transporter interface { transport.Transporter Request() *http.Request Client() *mqtt.Client Message() *mqtt.Message }
Transporter is mqtt Transporter
type WalkRouteFunc ¶
WalkRouteFunc is the type of the function called for each route visited by Walk.