Documentation ¶
Index ¶
- Variables
- type Client
- func New(transport transport.Transport, creds transport.Credentials, ...) (*Client, error)
- func NewFromConnectionString(transport transport.Transport, cs string, opts ...ClientOption) (*Client, error)
- func NewFromX509Cert(transport transport.Transport, deviceID, hostName string, crt *tls.Certificate, ...) (*Client, error)
- func NewFromX509FromFile(transport transport.Transport, deviceID, hostname, certFile, keyFile string, ...) (*Client, error)
- func (c *Client) Close() error
- func (c *Client) Connect(ctx context.Context) error
- func (c *Client) CreateModule(ctx context.Context, m *iotservice.Module) (*iotservice.Module, error)
- func (c *Client) DeleteModule(ctx context.Context, m *iotservice.Module) error
- func (c *Client) DeviceID() string
- func (c *Client) GetModule(ctx context.Context, moduleID string) (*iotservice.Module, error)
- func (c *Client) ListModules(ctx context.Context) ([]*iotservice.Module, error)
- func (c *Client) RegisterMethod(ctx context.Context, name string, fn DirectMethodHandler) error
- func (c *Client) RetrieveTwinState(ctx context.Context) (desired, reported TwinState, err error)
- func (c *Client) SendEvent(ctx context.Context, payload []byte, opts ...SendOption) error
- func (c *Client) SubscribeEvents(ctx context.Context) (*EventSub, error)
- func (c *Client) SubscribeTwinUpdates(ctx context.Context) (*TwinStateSub, error)
- func (c *Client) UnregisterMethod(name string)
- func (c *Client) UnsubscribeEvents(sub *EventSub)
- func (c *Client) UnsubscribeTwinUpdates(sub *TwinStateSub)
- func (c *Client) UpdateModule(ctx context.Context, m *iotservice.Module) (*iotservice.Module, error)
- func (c *Client) UpdateTwinState(ctx context.Context, s TwinState) (int, error)
- func (c *Client) UploadFile(ctx context.Context, blobName string, file io.Reader, size int64) error
- type ClientOption
- type DirectMethodHandler
- type EventSub
- type ModuleClient
- func NewModule(transport transport.Transport, creds transport.Credentials, ...) (*ModuleClient, error)
- func NewModuleFromConnectionString(transport transport.Transport, ...) (*ModuleClient, error)
- func NewModuleFromEnvironment(transport transport.Transport, edge bool, opts ...ClientOption) (*ModuleClient, error)
- func (c *ModuleClient) Broker() string
- func (c *ModuleClient) Gateway() string
- func (c *ModuleClient) GenerationID() string
- func (c *ModuleClient) ModuleID() string
- func (c *ModuleClient) SubscribeTwinUpdates(ctx context.Context) (*TwinStateSub, error)
- func (c *ModuleClient) UnsubscribeTwinUpdates(sub *TwinStateSub)
- type ModuleSharedAccessKeyCredentials
- func (c *ModuleSharedAccessKeyCredentials) GetBroker() string
- func (c *ModuleSharedAccessKeyCredentials) GetCertificate() *tls.Certificate
- func (c *ModuleSharedAccessKeyCredentials) GetGateway() string
- func (c *ModuleSharedAccessKeyCredentials) GetGenerationID() string
- func (c *ModuleSharedAccessKeyCredentials) GetModuleID() string
- func (c *ModuleSharedAccessKeyCredentials) GetSAK() string
- func (c *ModuleSharedAccessKeyCredentials) GetWorkloadURI() string
- func (c *ModuleSharedAccessKeyCredentials) UseEdgeGateway() bool
- type SendOption
- func WithSendCorrelationID(cid string) SendOption
- func WithSendCreationTime(t time.Time) SendOption
- func WithSendExpiryTime(t time.Time) SendOption
- func WithSendMessageID(mid string) SendOption
- func WithSendProperties(m map[string]string) SendOption
- func WithSendProperty(k, v string) SendOption
- func WithSendQoS(qos int) SendOption
- type SharedAccessKeyCredentials
- func (c *SharedAccessKeyCredentials) GetBroker() string
- func (c *SharedAccessKeyCredentials) GetCertificate() *tls.Certificate
- func (c *SharedAccessKeyCredentials) GetDeviceID() string
- func (c *SharedAccessKeyCredentials) GetGateway() string
- func (c *SharedAccessKeyCredentials) GetGenerationID() string
- func (c *SharedAccessKeyCredentials) GetHostName() string
- func (c *SharedAccessKeyCredentials) GetModuleID() string
- func (c *SharedAccessKeyCredentials) GetSAK() string
- func (c *SharedAccessKeyCredentials) GetWorkloadURI() string
- func (c *SharedAccessKeyCredentials) UseEdgeGateway() bool
- type TwinState
- type TwinStateSub
- type X509Credentials
- func (c *X509Credentials) GetBroker() string
- func (c *X509Credentials) GetCertificate() *tls.Certificate
- func (c *X509Credentials) GetDeviceID() string
- func (c *X509Credentials) GetGateway() string
- func (c *X509Credentials) GetGenerationID() string
- func (c *X509Credentials) GetHostName() string
- func (c *X509Credentials) GetModuleID() string
- func (c *X509Credentials) GetSAK() string
- func (c *X509Credentials) GetWorkloadURI() string
- func (c *X509Credentials) Token(resource string, lifetime time.Duration) (*common.SharedAccessSignature, error)
- func (c *X509Credentials) TokenFromEdge(workloadURI, module, genid, resource string, lifetime time.Duration) (*common.SharedAccessSignature, error)
- func (c *X509Credentials) UseEdgeGateway() bool
Constants ¶
This section is empty.
Variables ¶
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( transport transport.Transport, creds transport.Credentials, opts ...ClientOption, ) (*Client, error)
New returns new iothub client.
func NewFromConnectionString ¶ added in v0.4.0
func NewFromConnectionString( transport transport.Transport, cs string, opts ...ClientOption, ) (*Client, error)
NewFromConnectionString creates a device client based on the given connection string.
func NewFromX509Cert ¶ added in v0.4.0
func NewFromX509Cert( transport transport.Transport, deviceID, hostName string, crt *tls.Certificate, opts ...ClientOption, ) (*Client, error)
func NewFromX509FromFile ¶ added in v0.4.0
func (*Client) Connect ¶
Connect connects to the iothub all subsequent calls will block until this function finishes with no error so it's the client's responsibility to connect in the background by running it in a goroutine and control other method invocations or calls in a synchronous way.
func (*Client) CreateModule ¶ added in v0.9.1
func (c *Client) CreateModule(ctx context.Context, m *iotservice.Module) (*iotservice.Module, error)
CreateModule Creates adds the given module to the registry.
func (*Client) DeleteModule ¶ added in v0.9.1
DeleteModule removes the named device module.
func (*Client) ListModules ¶ added in v0.9.1
ListModules list all the registered modules on the device.
func (*Client) RegisterMethod ¶
RegisterMethod registers the given direct method handler, returns an error when method is already registered. If fn returns an error and empty body its error string used as value of the error attribute in the result json.
func (*Client) RetrieveTwinState ¶
RetrieveTwinState returns desired and reported twin device states.
func (*Client) SubscribeEvents ¶
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 ¶
UnregisterMethod unregisters the named method.
func (*Client) UnsubscribeEvents ¶
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) UpdateModule ¶ added in v0.9.1
func (c *Client) UpdateModule(ctx context.Context, m *iotservice.Module) (*iotservice.Module, error)
UpdateModule updates the given module.
func (*Client) UpdateTwinState ¶
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)
ClientOption is a client configuration option.
func WithLogger ¶
func WithLogger(l logger.Logger) ClientOption
WithLogger changes default logger, default it an stdout logger.
type DirectMethodHandler ¶
type DirectMethodHandler func(payload map[string]interface{}) ( code int, response map[string]interface{}, err error, )
DirectMethodHandler handles direct method invocations.
type ModuleClient ¶ added in v0.6.1
type ModuleClient struct {
Client
}
ModuleClient is iothub device client adapted for use with a module connection
func NewModule ¶ added in v0.6.1
func NewModule( transport transport.Transport, creds transport.Credentials, opts ...ClientOption, ) (*ModuleClient, error)
NewModule returns a new ModuleClient struct
func NewModuleFromConnectionString ¶ added in v0.6.1
func NewModuleFromConnectionString( transport transport.Transport, cs, gatewayHostName, moduleGenerationID, workloadURI string, edge bool, opts ...ClientOption, ) (*ModuleClient, error)
NewModuleFromConnectionString returns a ModuleClient struct with credentials based off of a supplied connection string
func NewModuleFromEnvironment ¶ added in v0.6.1
func NewModuleFromEnvironment( transport transport.Transport, edge bool, opts ...ClientOption, ) (*ModuleClient, error)
func (*ModuleClient) Broker ¶ added in v0.6.1
func (c *ModuleClient) Broker() string
Broker returns broker property from client's credential property
func (*ModuleClient) Gateway ¶ added in v0.6.1
func (c *ModuleClient) Gateway() string
Gateway returns gateway hostname property from client's credential property
func (*ModuleClient) GenerationID ¶ added in v0.6.1
func (c *ModuleClient) GenerationID() string
GenerationID returns generation ID property from client's credential property
func (*ModuleClient) ModuleID ¶ added in v0.6.1
func (c *ModuleClient) ModuleID() string
ModuleID returns module ID property from client's credential property
func (*ModuleClient) SubscribeTwinUpdates ¶ added in v0.9.1
func (c *ModuleClient) SubscribeTwinUpdates(ctx context.Context) (*TwinStateSub, error)
SubscribeTwinUpdates subscribes to module desired state changes. It returns a channel to read the twin updates from.
func (*ModuleClient) UnsubscribeTwinUpdates ¶ added in v0.9.1
func (c *ModuleClient) UnsubscribeTwinUpdates(sub *TwinStateSub)
UnsubscribeTwinUpdates unsubscribes the given handler from twin state updates.
type ModuleSharedAccessKeyCredentials ¶ added in v0.6.1
type ModuleSharedAccessKeyCredentials struct {}
ModuleSharedAccessKeyCredentials is a SharedAccessKeyCredentials struct adapted for module connections
func ParseModuleConnectionString ¶ added in v0.6.1
func ParseModuleConnectionString(cs string) (*ModuleSharedAccessKeyCredentials, error)
ParseModuleConnectionString returns a ModuleSharedAccessKeyCredentials struct with some properties derived from a supplied connection string
func ParseModuleEnvironmentVariables ¶ added in v0.6.1
func ParseModuleEnvironmentVariables() (*ModuleSharedAccessKeyCredentials, error)
func (*ModuleSharedAccessKeyCredentials) GetBroker ¶ added in v0.6.1
func (c *ModuleSharedAccessKeyCredentials) GetBroker() string
GetBroker returns gateway host name if UseEdgeGateway is true, else returns IoT Hub host name
func (*ModuleSharedAccessKeyCredentials) GetCertificate ¶ added in v0.6.1
func (c *ModuleSharedAccessKeyCredentials) GetCertificate() *tls.Certificate
GetCertificate returns nil. Only here to satisfy Credentials interface
func (*ModuleSharedAccessKeyCredentials) GetGateway ¶ added in v0.6.1
func (c *ModuleSharedAccessKeyCredentials) GetGateway() string
GetGateway returns Gateway Host Name
func (*ModuleSharedAccessKeyCredentials) GetGenerationID ¶ added in v0.6.1
func (c *ModuleSharedAccessKeyCredentials) GetGenerationID() string
GetGenerationID returns GenerationID
func (*ModuleSharedAccessKeyCredentials) GetModuleID ¶ added in v0.6.1
func (c *ModuleSharedAccessKeyCredentials) GetModuleID() string
GetModuleID returns ModuleID
func (*ModuleSharedAccessKeyCredentials) GetSAK ¶ added in v0.6.1
func (c *ModuleSharedAccessKeyCredentials) GetSAK() string
GetSAK returns SharedAccessKey
func (*ModuleSharedAccessKeyCredentials) GetWorkloadURI ¶ added in v0.6.1
func (c *ModuleSharedAccessKeyCredentials) GetWorkloadURI() string
GetWorkloadURI returns the URI of the IoT Edge workload API
func (*ModuleSharedAccessKeyCredentials) UseEdgeGateway ¶ added in v0.6.1
func (c *ModuleSharedAccessKeyCredentials) UseEdgeGateway() bool
UseEdgeGateway returns bool to connect via edgeHub or directly to IoT Hub
type SendOption ¶
SendOption is a send event options.
func WithSendCorrelationID ¶
func WithSendCorrelationID(cid string) SendOption
WithSendCorrelationID sets message correlation id.
func WithSendCreationTime ¶ added in v0.8.0
func WithSendCreationTime(t time.Time) SendOption
func WithSendExpiryTime ¶ added in v0.8.0
func WithSendExpiryTime(t time.Time) SendOption
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 {}
func ParseConnectionString ¶ added in v0.4.0
func ParseConnectionString(cs string) (*SharedAccessKeyCredentials, error)
func (*SharedAccessKeyCredentials) GetBroker ¶ added in v0.6.1
func (c *SharedAccessKeyCredentials) GetBroker() string
GetBroker not implemented for SharedAccessKeyCredentials
func (*SharedAccessKeyCredentials) GetCertificate ¶ added in v0.3.0
func (c *SharedAccessKeyCredentials) GetCertificate() *tls.Certificate
GetCertificate not implemented for SharedAccessKeyCredentials
func (*SharedAccessKeyCredentials) GetDeviceID ¶ added in v0.3.0
func (c *SharedAccessKeyCredentials) GetDeviceID() string
func (*SharedAccessKeyCredentials) GetGateway ¶ added in v0.6.1
func (c *SharedAccessKeyCredentials) GetGateway() string
GetGateway not implemented for SharedAccessKeyCredentials
func (*SharedAccessKeyCredentials) GetGenerationID ¶ added in v0.6.1
func (c *SharedAccessKeyCredentials) GetGenerationID() string
GetGenerationID not implemented for SharedAccessKeyCredentials
func (*SharedAccessKeyCredentials) GetHostName ¶ added in v0.3.0
func (c *SharedAccessKeyCredentials) GetHostName() string
func (*SharedAccessKeyCredentials) GetModuleID ¶ added in v0.6.1
func (c *SharedAccessKeyCredentials) GetModuleID() string
GetModuleID not implemented for SharedAccessKeyCredentials
func (*SharedAccessKeyCredentials) GetSAK ¶ added in v0.6.1
func (c *SharedAccessKeyCredentials) GetSAK() string
GetSAK not implemented for SharedAccessKeyCredentials
func (*SharedAccessKeyCredentials) GetWorkloadURI ¶ added in v0.6.1
func (c *SharedAccessKeyCredentials) GetWorkloadURI() string
GetWorkloadURI not implemented for SharedAccessKeyCredentials
func (*SharedAccessKeyCredentials) UseEdgeGateway ¶ added in v0.6.1
func (c *SharedAccessKeyCredentials) UseEdgeGateway() bool
UseEdgeGateway not implemented for SharedAccessKeyCredentials
type TwinState ¶
type TwinState map[string]interface{}
TwinState is both desired and reported twin device's state.
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) GetBroker ¶ added in v0.6.1
func (c *X509Credentials) GetBroker() string
GetBroker not implemented for X509Credentials
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) GetGateway ¶ added in v0.6.1
func (c *X509Credentials) GetGateway() string
GetGateway not implemented for X509Credentials
func (*X509Credentials) GetGenerationID ¶ added in v0.6.1
func (c *X509Credentials) GetGenerationID() string
GetGenerationID not implemented for X509Credentials
func (*X509Credentials) GetHostName ¶ added in v0.3.0
func (c *X509Credentials) GetHostName() string
func (*X509Credentials) GetModuleID ¶ added in v0.6.1
func (c *X509Credentials) GetModuleID() string
GetModuleID not implemented for X509Credentials
func (*X509Credentials) GetSAK ¶ added in v0.6.1
func (c *X509Credentials) GetSAK() string
GetSAK not implemented for X509Credentials
func (*X509Credentials) GetWorkloadURI ¶ added in v0.6.1
func (c *X509Credentials) GetWorkloadURI() string
GetWorkloadURI not implemented for X509Credentials
func (*X509Credentials) Token ¶ added in v0.3.0
func (c *X509Credentials) Token( resource string, lifetime time.Duration, ) (*common.SharedAccessSignature, error)
func (*X509Credentials) TokenFromEdge ¶ added in v0.6.1
func (c *X509Credentials) TokenFromEdge( workloadURI, module, genid, resource string, lifetime time.Duration, ) (*common.SharedAccessSignature, error)
TokenFromEdge not implemented for X509Credentials
func (*X509Credentials) UseEdgeGateway ¶ added in v0.6.1
func (c *X509Credentials) UseEdgeGateway() bool
UseEdgeGateway not implemented for X509Credentials
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package iotdevicetest provides utilities for iotdevice testing.
|
Package iotdevicetest provides utilities for iotdevice testing. |