Documentation ¶
Index ¶
- Constants
- func FromAMQPMessage(msg *amqp.Message) *common.Message
- func NewSymmetricKey() (string, error)
- type AuthType
- type Authentication
- type CallOption
- type Client
- func (c *Client) Call(ctx context.Context, deviceID string, methodName string, ...) (*Result, error)
- func (c *Client) CancelJob(ctx context.Context, jobID string) (map[string]interface{}, error)
- func (c *Client) Close() error
- func (c *Client) CreateDevice(ctx context.Context, device *Device) (*Device, error)
- func (c *Client) DeleteDevice(ctx context.Context, deviceID string) error
- func (c *Client) DeviceConnectionString(device *Device, secondary bool) (string, error)
- func (c *Client) DeviceSAS(device *Device, duration time.Duration, secondary bool) (string, error)
- func (c *Client) ExportDevicesToBlob(ctx context.Context, outputBlobURL string, excludeKeys bool) (map[string]interface{}, error)
- func (c *Client) GetDevice(ctx context.Context, deviceID string) (*Device, error)
- func (c *Client) GetJob(ctx context.Context, jobID string) (map[string]interface{}, error)
- func (c *Client) GetTwin(ctx context.Context, deviceID string) (*Twin, error)
- func (c *Client) HostName() string
- func (c *Client) ImportDevicesFromBlob(ctx context.Context, inputBlobURL string, outputBlobURL string) (map[string]interface{}, error)
- func (c *Client) ListDevices(ctx context.Context) ([]*Device, error)
- func (c *Client) ListJobs(ctx context.Context) ([]map[string]interface{}, error)
- func (c *Client) SendEvent(ctx context.Context, deviceID string, payload []byte, opts ...SendOption) error
- func (c *Client) Stats(ctx context.Context) (*Stats, error)
- func (c *Client) SubscribeEvents(ctx context.Context, fn EventHandler) error
- func (c *Client) SubscribeFeedback(ctx context.Context, fn FeedbackHandler) error
- func (c *Client) UpdateDevice(ctx context.Context, device *Device) (*Device, error)
- func (c *Client) UpdateTwin(ctx context.Context, deviceID string, twin *Twin, etag string) (*Twin, error)
- type ClientOption
- type Device
- type Event
- type EventHandler
- type Feedback
- type FeedbackHandler
- type Properties
- type Result
- type SendOption
- func WithSendAck(typ string) SendOption
- func WithSendCorrelationID(cid string) SendOption
- func WithSendMessageID(mid string) SendOption
- func WithSendProperties(m map[string]string) SendOption
- func WithSendProperty(k, v string) SendOption
- func WithSendUserID(uid string) SendOption
- func WithSentExpiryTime(t time.Time) SendOption
- type Stats
- type SymmetricKey
- type Twin
- type X509Thumbprint
Constants ¶
const ( // AckNone no feedback. AckNone = "none" // AckPositive receive a feedback message if the message was completed. AckPositive = "positive" // AckNegative receive a feedback message if the message expired // (or maximum delivery count was reached) without being completed by the device. AckNegative = "negative" // AckFull both positive and negative. AckFull = "full" )
const ( // AuthSAS uses symmetric keys to sign requests. AuthSAS = "sas" // AuthSelfSigned self signed certificate with a thumbprint. AuthSelfSigned = "selfSigned" // AuthCA certificate signed by a registered certificate authority. AuthCA = "certificateAuthority" )
Variables ¶
This section is empty.
Functions ¶
func FromAMQPMessage ¶
FromAMQPMessage converts a amqp.Message into common.Message.
Exported to use with a custom stream when devices telemetry is routed for example to an EventhHub instance.
func NewSymmetricKey ¶
NewSymmetricKey generates a random symmetric key.
Types ¶
type Authentication ¶
type Authentication struct { SymmetricKey *SymmetricKey `json:"symmetricKey,omitempty"` X509Thumbprint *X509Thumbprint `json:"x509Thumbprint,omitempty"` Type AuthType `json:"type,omitempty"` }
type CallOption ¶
type CallOption func(c *call) error
CallOption is a direct-method invocation option.
func WithCallConnectTimeout ¶
func WithCallConnectTimeout(seconds int) CallOption
ConnectTimeout is connection timeout in seconds.
func WithCallResponseTimeout ¶
func WithCallResponseTimeout(seconds int) CallOption
ResponseTimeout is response timeout in seconds.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func New ¶
func New(opts ...ClientOption) (*Client, error)
NewLogger creates new iothub service client.
func (*Client) Call ¶
func (c *Client) Call( ctx context.Context, deviceID string, methodName string, payload map[string]interface{}, opts ...CallOption, ) (*Result, error)
Call calls the named direct method on with the given parameters.
func (*Client) CreateDevice ¶
CreateDevice creates a new device.
func (*Client) DeleteDevice ¶
DeleteDevice deletes the named device.
func (*Client) DeviceConnectionString ¶
DeviceConnectionString builds up a connection string for the given device.
func (*Client) ExportDevicesToBlob ¶
func (*Client) ImportDevicesFromBlob ¶
func (*Client) ListDevices ¶
ListDevices lists all registered devices.
func (*Client) SendEvent ¶
func (c *Client) SendEvent( ctx context.Context, deviceID string, payload []byte, opts ...SendOption, ) error
SendEvent sends the given cloud-to-device message and returns its id. Panics when event is nil.
func (*Client) SubscribeEvents ¶
func (c *Client) SubscribeEvents(ctx context.Context, fn EventHandler) error
SubscribeEvents subscribes to D2C events.
Event handler is blocking, handle asynchronous processing on your own.
func (*Client) SubscribeFeedback ¶
func (c *Client) SubscribeFeedback(ctx context.Context, fn FeedbackHandler) error
SubscribeFeedback subscribes to feedback of messages that ack was requested.
func (*Client) UpdateDevice ¶
UpdateDevice updates the named device.
type ClientOption ¶
ClientOption is a client configuration option.
func WithConnectionString ¶
func WithConnectionString(cs string) ClientOption
WithConnectionString parses the given connection string instead of using `WithCredentials`.
func WithCredentials ¶
func WithCredentials(creds *credentials.Credentials) ClientOption
WithCredentials uses the given credentials to generate GenerateToken tokens.
func WithHTTPClient ¶
func WithHTTPClient(client *http.Client) ClientOption
WithHTTPClient changes default http rest client.
func WithTLSConfig ¶ added in v0.1.0
func WithTLSConfig(config *tls.Config) ClientOption
WithTLSConfig sets TLS config that's used by REST HTTP and AMQP clients.
type Device ¶
type Device struct { DeviceID string `json:"deviceId,omitempty"` GenerationID string `json:"generationId,omitempty"` ETag string `json:"etag,omitempty"` ConnectionState string `json:"connectionState,omitempty"` Status string `json:"status,omitempty"` StatusReason string `json:"statusReason,omitempty"` ConnectionStateUpdatedTime string `json:"connectionStateUpdatedTime,omitempty"` StatusUpdatedTime string `json:"statusUpdatedTime,omitempty"` LastActivityTime string `json:"lastActivityTime,omitempty"` CloudToDeviceMessageCount int `json:"cloudToDeviceMessageCount,omitempty"` Authentication *Authentication `json:"authentication,omitempty"` Capabilities map[string]interface{} `json:"capabilities,omitempty"` }
type EventHandler ¶ added in v0.1.0
EventHandler handles incoming cloud-to-device events.
type Feedback ¶
type Feedback struct { OriginalMessageID string `json:"originalMessageId"` Description string `json:"description"` DeviceGenerationID string `json:"deviceGenerationId"` DeviceID string `json:"deviceId"` EnqueuedTimeUTC time.Time `json:"enqueuedTimeUtc"` StatusCode string `json:"statusCode"` }
Feedback is message feedback.
type FeedbackHandler ¶
type FeedbackHandler func(f *Feedback)
FeedbackHandler handles message feedback.
type Properties ¶
type Result ¶
type Result struct { Status int `json:"status,omitempty"` Payload map[string]interface{} `json:"payload,omitempty"` }
Result is a direct-method call result.
type SendOption ¶
SendOption is a send option.
func WithSendAck ¶
func WithSendAck(typ string) SendOption
WithSendAck sets message confirmation type.
func WithSendCorrelationID ¶
func WithSendCorrelationID(cid string) SendOption
WithSendCorrelationID sets 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 property.
func WithSentExpiryTime ¶
func WithSentExpiryTime(t time.Time) SendOption
WithSentExpiryTime sets message expiration time.
type SymmetricKey ¶
type Twin ¶
type Twin struct { DeviceID string `json:"deviceId,omitempty"` ETag string `json:"etag,omitempty"` DeviceETag string `json:"deviceEtag,omitempty"` Status string `json:"status,omitempty"` StatusReason string `json:"statusReason,omitempty"` StatusUpdateTime string `json:"statusUpdateTime,omitempty"` ConnectionState string `json:"connectionState,omitempty"` LastActivityTime string `json:"lastActivityTime,omitempty"` CloudToDeviceMessageCount int `json:"cloudToDeviceMessageCount,omitempty"` AuthenticationType string `json:"authenticationType,omitempty"` X509Thumbprint *X509Thumbprint `json:"x509Thumbprint,omitempty"` Version int `json:"version,omitempty"` Tags map[string]interface{} `json:"tags,omitempty"` Properties *Properties `json:"properties,omitempty"` Capabilities map[string]interface{} `json:"capabilities,omitempty"` }