smqtt

package module
v0.0.0-...-2cce9ca Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 2, 2020 License: MIT Imports: 14 Imported by: 0

README

simplemqtt

一个类gin的MQTT框架(基于paho.mqtt.golang)

Documentation

Overview

Package smqtt implements functions for manipulation of MQTT API. It provides a gin-like way to create MQTT API.

Package smqtt implements functions for manipulation of MQTT API. It provides a gin-like way to create MQTT API.

Package smqtt implements functions for manipulation of MQTT API. It provides a gin-like way to create MQTT API.

Package smqtt implements functions for manipulation of MQTT API. It provides a gin-like way to create MQTT API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClientError

func ClientError(err_str string) error

func InternalError

func InternalError(err_str string) error

func ParamRequiredError

func ParamRequiredError(param_name string) error

func SessionID

func SessionID() string

Types

type Cache

type Cache interface {
	Get(key string) (string, error)
	Set(key string, value interface{}, expiration time.Duration) error
}

type ClientConfig

type ClientConfig struct {
	Broker         string
	ClientId       string
	CaCertPath     string
	ClientCertPath string
	ClientKeyPath  string
	KeepAlive      int
	PingTimeout    int
	CleanSession   bool
	OrderMatters   bool
}

type Config

type Config struct {
	Name       string
	Dedup      bool
	Prefix     string
	Expiration int
	Client     *ClientConfig
}

func (*Config) Default

func (c *Config) Default() *Config

type Context

type Context struct {
	// contains filtered or unexported fields
}

Context allows us to pass variables between middleware, manage the flow, validate the JSON of a MQTT Message and render a JSON response.

func (*Context) Abort

func (c *Context) Abort()

Abort is used to abort the execution of context.handlers.

func (*Context) BindJSON

func (c *Context) BindJSON(obj interface{}) error

BindJSON is used to unmarshal the MQTT message to obj

func (*Context) Get

func (c *Context) Get(key string) (value interface{}, exists bool)

Get returns the value for the given key.

func (*Context) MustGet

func (c *Context) MustGet(key string) interface{}

MustGet returns the value for the given key if it existes, otherwise it panics.

func (*Context) Next

func (c *Context) Next()

Next is used to execute context.handlers[context.index+1:]

func (*Context) Payload

func (c *Context) Payload() []byte

func (*Context) Qos

func (c *Context) Qos() byte

func (*Context) Respond

func (c *Context) Respond(topic string, qos byte, retained bool, msg []byte) error

Respond is used to write and send a MQTT message to certain topic as response

func (*Context) Session

func (c *Context) Session() string

func (*Context) Set

func (c *Context) Set(key string, value interface{})

Set is used to store a new key/value pair in COntext.keys. It will create an empty map when context.keys is currently nil.

func (*Context) Start

func (c *Context) Start()

Start is used to call context.handlers[0]

func (*Context) Topic

func (c *Context) Topic() string

type Group

type Group struct {
	// contains filtered or unexported fields
}

Group allows us to create MQTT API and manipulate them as a group.

func (*Group) Listen

func (group *Group) Listen(sub_topic string, qos byte, handler ...Handler) error

Listen is used to make real subscription to MQTT broker.

func (*Group) Use

func (group *Group) Use(handler ...Handler)

Use adds middleware to group.handlers.

type Handler

type Handler func(*Context)

This definition indicates that a handler implementaion must and only has a *Context as parameter

type Response

type Response struct {
	Topic string
	Qos   byte
	Msg   []byte
}

When a response is rendered using context.Respond, it will be recorded in context.keys in the form of Response.

type Router

type Router struct {
	// contains filtered or unexported fields
}

Router allows us to create Group and read/write MQTT message

func NewRouter

func NewRouter(conf *Config, mids Cache) (*Router, error)

NewRouter returns a *Router that uses two default middlewares logger and recovery

func (*Router) Group

func (router *Router) Group(topic string) *Group

Group creates a new group

func (*Router) Use

func (router *Router) Use(handler ...Handler)

Use add middlewares to router.group.handlers

Directories

Path Synopsis
Package smqtt implements functions for manipulation of MQTT API.
Package smqtt implements functions for manipulation of MQTT API.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL