lib

package
v0.0.0-...-7615cdf Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2018 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MessageHandler = map[string]MessageHandlerFunction{
	"clear":      clear,
	"commit":     commit,
	"put":        put,
	"disconnect": remove,
	"response":   response,
	"event":      event,
	"delete":     deleteHandler,
}

Functions

func CheckExecutionAccess

func CheckExecutionAccess(resource string, cred *Credentials) (err error)

func ClearGateway

func ClearGateway(id string, cred *Credentials) (err error)

func ClearPts

func ClearPts() (err error)

func CloseProducer

func CloseProducer()

func CommitGateway

func CommitGateway(id string, gateway model.GatewayRef, cred *Credentials) (err error)

func CreateIotDevice

func CreateIotDevice(device model.ConnectorDevice, cred *Credentials) (result iot_model.DeviceInstance, err error)

func DeleteDeviceInstance

func DeleteDeviceInstance(uri string, cred *Credentials) (err error)

func DeregisterPts

func DeregisterPts(device string) (err error)

func DeviceInstanceToDeviceServiceEntity

func DeviceInstanceToDeviceServiceEntity(device iot_model.DeviceInstance, dtCache *map[string]model.ShortDeviceType, cred *Credentials) (entity model.DeviceServiceEntity, err error)

func DeviceUrlToIotDevice

func DeviceUrlToIotDevice(deviceUrl string, cred *Credentials) (entities []model.DeviceServiceEntity, err error)

func GetDeviceType

func GetDeviceType(id string, cred *Credentials) (dt model.ShortDeviceType, err error)

func GetGateway

func GetGateway(id string, cred *Credentials) (gateway model.Gateway, err error)

func GetOpenidToken

func GetOpenidToken(username, password string, token *OpenidToken) (err error)

func HandleMessage

func HandleMessage(msg string)

func IndexTags

func IndexTags(tags []string) (result map[string]string)

func InitConnectionLog

func InitConnectionLog()

func InitConsumer

func InitConsumer()

func InitProducer

func InitProducer() sarama.AsyncProducer

func LogDeviceState

func LogDeviceState(id string, state string, desc string) (err error)

deprecated

func MergeTagIndexes

func MergeTagIndexes(platform map[string]string, client map[string]string) (result map[string]string)

func NewSession

func NewSession(connection *websocket.Conn)

func Produce

func Produce(topic string, message string)

func RefreshOpenidToken

func RefreshOpenidToken(token *OpenidToken) (err error)

func RegisterPts

func RegisterPts(device string) (err error)

func TagIndexToTagList

func TagIndexToTagList(index map[string]string) (tags []string)

func UpdateDeviceInstance

func UpdateDeviceInstance(device iot_model.DeviceInstance, cred *Credentials) (err error)

func WsStart

func WsStart()

Types

type ConnectorLog

type ConnectorLog struct {
	Connected bool         `json:"connected"`
	Connector string       `json:"connector"`
	Gateways  []GatewayLog `json:"gateways"`
	Devices   []DeviceLog  `json:"devices"`
	Time      time.Time    `json:"time"`
}

func (ConnectorLog) Send

func (this ConnectorLog) Send() error

type Credentials

type Credentials struct {
	User         string          `json:"user"`
	Pw           string          `json:"pw"`
	Token        string          `json:"token"` //responsetoken if needed
	Gateway      string          `json:"gid"`
	Openid       *OpenidToken    `json:"-"`
	ErrorHandler func(err error) `json:"-"`
}

func WsHandshake

func WsHandshake(conn *websocket.Conn) (credentials *Credentials, err error)

func (*Credentials) Delete

func (this *Credentials) Delete(url string, body io.Reader) (resp *http.Response, err error)

func (*Credentials) EnsureAccess

func (this *Credentials) EnsureAccess() (err error)

func (*Credentials) Get

func (this *Credentials) Get(url string) (resp *http.Response, err error)

func (*Credentials) Post

func (this *Credentials) Post(url string, contentType string, body io.Reader) (resp *http.Response, err error)

type DeviceLog

type DeviceLog struct {
	Connected bool      `json:"connected"`
	Connector string    `json:"connector"`
	Device    string    `json:"device"`
	Time      time.Time `json:"time"`
}

func (DeviceLog) Send

func (this DeviceLog) Send() error

type DeviceLogMsg

type DeviceLogMsg struct {
	Id    string `json:"id"`
	State string `json:"state"`
	Desc  string `json:"desc"`
}

type Envelope

type Envelope struct {
	DeviceId  string      `json:"device_id,omitempty"`
	ServiceId string      `json:"service_id,omitempty"`
	Value     interface{} `json:"value"`
}

type GatewayLog

type GatewayLog struct {
	Connected bool      `json:"connected"`
	Connector string    `json:"connector"`
	Gateway   string    `json:"gateway"`
	Time      time.Time `json:"time"`
}

func (GatewayLog) Send

func (this GatewayLog) Send() error

type IotErrorMessage

type IotErrorMessage struct {
	StatusCode int      `json:"status_code,omitempty"`
	Message    string   `json:"message"`
	ErrorCode  string   `json:"error_code,omitempty"`
	Detail     []string `json:"detail,omitempty"`
}

type Message

type Message struct {
	Status      int         `json:"status"`
	Handler     string      `json:"handler"`
	Token       string      `json:"token"`
	ContentType string      `json:"content_type"`
	Payload     interface{} `json:"payload"`
}

func (Message) Str

func (this Message) Str() string

type MessageHandlerFunction

type MessageHandlerFunction func(session *Session, request Request)

type OpenidToken

type OpenidToken struct {
	AccessToken      string    `json:"access_token"`
	ExpiresIn        float64   `json:"expires_in"`
	RefreshExpiresIn float64   `json:"refresh_expires_in"`
	RefreshToken     string    `json:"refresh_token"`
	TokenType        string    `json:"token_type"`
	RequestTime      time.Time `json:"-"`
}

type RawRequest

type RawRequest struct {
	Handler string      `json:"handler,omitempty"`
	Token   string      `json:"token,omitempty"`
	Payload interface{} `json:"payload,omitempty"`
}

type Request

type Request struct {
	Handler     string
	Token       string
	ContentType string
	RawPayload  interface{}
	// contains filtered or unexported fields
}

func (*Request) Error

func (this *Request) Error(msg string) (err error)

func (*Request) Payload

func (this *Request) Payload(result interface{}) (err error)

func (*Request) Respond

func (this *Request) Respond(payload interface{}) (err error)

func (*Request) UserError

func (this *Request) UserError(msg string) (err error)

type Session

type Session struct {
	Id       string
	Prefixes []string
	Cred     *Credentials

	Mux      sync.Mutex
	UriCache map[string]model.DeviceServiceEntity

	ConsecutiveErrors int64
	Gateway           string
	// contains filtered or unexported fields
}

func (*Session) Close

func (session *Session) Close(reason string)

func (*Session) GetEntity

func (session *Session) GetEntity(uri string) (entity model.DeviceServiceEntity, err error)

func (*Session) GetFormater

func (session *Session) GetFormater(cred *Credentials, deviceid string, serviceid string) (transformer formatter_lib.EventTransformer, err error)

func (*Session) HandleMessage

func (session *Session) HandleMessage(message string)

func (*Session) ListenToEntity

func (session *Session) ListenToEntity(entity model.DeviceServiceEntity) (err error)

func (*Session) LogConnect

func (session *Session) LogConnect()

func (*Session) LogConnectDevice

func (session *Session) LogConnectDevice(id string)

func (*Session) LogCreated

func (session *Session) LogCreated(devices []iot_model.DeviceInstance)

func (*Session) LogDisconnect

func (session *Session) LogDisconnect()

func (*Session) LogDisconnectDevice

func (session *Session) LogDisconnectDevice(id string)

func (*Session) LogGatewayConnect

func (session *Session) LogGatewayConnect()

func (*Session) MuteEntity

func (session *Session) MuteEntity(entity model.DeviceServiceEntity) (err error)

func (*Session) NewRequest

func (session *Session) NewRequest(message string) (result Request, err error)

func (*Session) SendClose

func (session *Session) SendClose(reason string) (err error)

func (*Session) SendCommand

func (session *Session) SendCommand(msg string) (err error)

func (*Session) SendError

func (session *Session) SendError(response Message) (err error)

func (*Session) SendResponse

func (session *Session) SendResponse(response Message) error

func (*Session) SendWsMsg

func (session *Session) SendWsMsg(msgType int, msg string) (err error)

func (*Session) Start

func (session *Session) Start()

type SessionsCollection

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

func Sessions

func Sessions() *SessionsCollection

func (*SessionsCollection) Close

func (this *SessionsCollection) Close()

func (*SessionsCollection) Deregister

func (this *SessionsCollection) Deregister(session *Session)

func (*SessionsCollection) DeregisterPrefix

func (this *SessionsCollection) DeregisterPrefix(session *Session, prefix string) (err error)

func (*SessionsCollection) Dispatch

func (this *SessionsCollection) Dispatch(prefix string, msg string)

func (*SessionsCollection) GetSessions

func (this *SessionsCollection) GetSessions() (result map[string]*Session)

func (*SessionsCollection) Register

func (this *SessionsCollection) Register(session *Session)

func (*SessionsCollection) RegisterPrefix

func (this *SessionsCollection) RegisterPrefix(session *Session, prefix string) (err error)

Jump to

Keyboard shortcuts

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