iotdevice

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2019 License: MIT Imports: 11 Imported by: 23

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("closed")

ErrClosed the client is already closed.

Functions

This section is empty.

Types

type Client

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

Client is iothub device client.

func New

func New(opts ...ClientOption) (*Client, error)

NewLogger returns new iothub client.

func (*Client) Close

func (c *Client) Close() error

Close closes transport connection.

func (*Client) Connect

func (c *Client) Connect(ctx context.Context) error

Connect connects to the iothub all subsequent calls will block until this function finishes with no error so it's clien's responsibility to connect in the background by running it in a goroutine and control other method invocations or call in in a synchronous way.

func (*Client) DeviceID

func (c *Client) DeviceID() string

DeviceID returns iothub device id.

func (*Client) RegisterMethod

func (c *Client) RegisterMethod(ctx context.Context, name string, fn DirectMethodHandler) error

RegisterMethod registers the given direct method handler, returns an error when method is already registered. If f returns an error and empty body its error string used as value of the error attribute in the result json.

func (*Client) RetrieveTwinState

func (c *Client) RetrieveTwinState(ctx context.Context) (desired TwinState, reported TwinState, err error)

RetrieveTwinState returns desired and reported twin device states.

func (*Client) SendEvent

func (c *Client) SendEvent(ctx context.Context, payload []byte, opts ...SendOption) error

SendEvent sends a device-to-cloud message. Panics when event is nil.

func (*Client) SubscribeEvents

func (c *Client) SubscribeEvents(ctx context.Context) (*EventSub, error)

SubscribeEvents subscribes to cloud-to-device events and returns a subscription struct.

func (*Client) SubscribeTwinUpdates

func (c *Client) SubscribeTwinUpdates(ctx context.Context) (*TwinStateSub, error)

SubscribeTwinUpdates registers fn as a desired state changes handler.

func (*Client) UnregisterMethod

func (c *Client) UnregisterMethod(name string)

UnregisterMethod unregisters the named method.

func (*Client) UnsubscribeEvents

func (c *Client) UnsubscribeEvents(sub *EventSub)

UnsubscribeEvents makes the given subscription to stop receiving messages.

func (*Client) UnsubscribeTwinUpdates

func (c *Client) UnsubscribeTwinUpdates(sub *TwinStateSub)

UnsubscribeTwinUpdates unsubscribes the given handler from twin state updates.

func (*Client) UpdateTwinState

func (c *Client) UpdateTwinState(ctx context.Context, s TwinState) (int, error)

UpdateTwinState updates twin device's state and returns new version. To remove any attribute set its value to nil.

type ClientOption

type ClientOption func(c *Client) error

ClientOption is a client configuration option.

func WithConnectionString

func WithConnectionString(cs string) ClientOption

WithConnectionString same as WithCredentials, but it parses the given connection string first.

func WithCredentials

func WithCredentials(creds transport.Credentials) ClientOption

WithCredentials sets custom authentication credentials, e.g. 3rd-party token provider.

func WithLogger

func WithLogger(l common.Logger) ClientOption

WithLogger changes default logger, default it an stdout logger.

func WithTransport

func WithTransport(tr transport.Transport) ClientOption

WithTransport changes default transport.

func WithX509FromCert

func WithX509FromCert(deviceID, hostname string, crt *tls.Certificate) ClientOption

WithX509FromCert enables x509 authentication.

func WithX509FromFile

func WithX509FromFile(deviceID, hostname, certFile, keyFile string) ClientOption

WithX509FromFile is same as `WithX509FromCert` but parses the given pem files first.

type DirectMethodHandler

type DirectMethodHandler func(p map[string]interface{}) (map[string]interface{}, error)

DirectMethodHandler handles direct method invocations.

type EventSub

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

func (*EventSub) C

func (s *EventSub) C() <-chan *common.Message

func (*EventSub) Err

func (s *EventSub) Err() error

type SendOption

type SendOption func(msg *common.Message) error

SendOption is a send event options.

func WithSendCorrelationID

func WithSendCorrelationID(cid string) SendOption

WithSendCorrelationID sets message correlation id.

func WithSendMessageID

func WithSendMessageID(mid string) SendOption

WithSendMessageID sets message id.

func WithSendProperties

func WithSendProperties(m map[string]string) SendOption

WithSendProperties same as `WithSendProperty` but accepts map of keys and values.

func WithSendProperty

func WithSendProperty(k, v string) SendOption

WithSendProperty sets a message option.

func WithSendQoS

func WithSendQoS(qos int) SendOption

WithSendQoS sets the quality of service (MQTT only). Only 0 and 1 values are supported, defaults to 1.

type SharedAccessKeyCredentials added in v0.3.0

type SharedAccessKeyCredentials struct {
	DeviceID string
	common.SharedAccessKey
}

func (*SharedAccessKeyCredentials) GetCertificate added in v0.3.0

func (c *SharedAccessKeyCredentials) GetCertificate() *tls.Certificate

func (*SharedAccessKeyCredentials) GetDeviceID added in v0.3.0

func (c *SharedAccessKeyCredentials) GetDeviceID() string

func (*SharedAccessKeyCredentials) GetHostName added in v0.3.0

func (c *SharedAccessKeyCredentials) GetHostName() string

type TwinState

type TwinState map[string]interface{}

TwinState is both desired and reported twin device's state.

func (TwinState) Version

func (s TwinState) Version() int

Version is state version.

type TwinStateSub

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

func (*TwinStateSub) C

func (s *TwinStateSub) C() <-chan TwinState

func (*TwinStateSub) Err

func (s *TwinStateSub) Err() error

type X509Credentials added in v0.3.0

type X509Credentials struct {
	HostName    string
	DeviceID    string
	Certificate *tls.Certificate
}

func (*X509Credentials) GetCertificate added in v0.3.0

func (c *X509Credentials) GetCertificate() *tls.Certificate

func (*X509Credentials) GetDeviceID added in v0.3.0

func (c *X509Credentials) GetDeviceID() string

func (*X509Credentials) GetHostName added in v0.3.0

func (c *X509Credentials) GetHostName() string

func (*X509Credentials) Token added in v0.3.0

func (c *X509Credentials) Token(
	resource string, lifetime time.Duration,
) (*common.SharedAccessSignature, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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