common

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: 12 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseConnectionString added in v0.3.0

func ParseConnectionString(cs string, require ...string) (map[string]string, error)

ParseConnectionString parses the given connection string into a key-value map, returns an error if at least one of required keys is missing.

func RootCAs

func RootCAs() *x509.CertPool

RootCAs root CA certificates pool for connecting to the cloud.

Types

type ConnectionAuthMethod added in v0.3.0

type ConnectionAuthMethod struct {
	Scope  string `json:"scope"`
	Type   string `json:"type"`
	Issuer string `json:"issuer"`
}

ConnectionAuthMethod is an authentication method of device-to-cloud communication.

type LevelLogger added in v0.1.0

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

LevelLogger is a logger that supports log levels.

func NewLogger added in v0.1.0

func NewLogger(name string, lvl LogLevel, print PrintFunc) *LevelLogger

NewLogger creates a new leveled logger instance with the given parameters.

func NewLoggerFromEnv added in v0.1.0

func NewLoggerFromEnv(name, key string) *LevelLogger

NewLoggerFromEnv returns a LevelLogger with the name prefix and severity based on the named environment variable or it falls back to LevelWarn if it's missing.

It uses the standard log.Print function for output so it can be controlled via the exposed configuration methods.

func (*LevelLogger) Debugf added in v0.1.0

func (l *LevelLogger) Debugf(format string, v ...interface{})

func (*LevelLogger) Errorf added in v0.1.0

func (l *LevelLogger) Errorf(format string, v ...interface{})

func (*LevelLogger) Infof added in v0.1.0

func (l *LevelLogger) Infof(format string, v ...interface{})

func (*LevelLogger) Warnf added in v0.1.0

func (l *LevelLogger) Warnf(format string, v ...interface{})

type LogLevel added in v0.1.0

type LogLevel uint8

LogLevel is logging severity.

const (
	LevelError LogLevel = iota
	LevelWarn
	LevelInfo
	LevelDebug
)

func (LogLevel) String added in v0.1.0

func (lvl LogLevel) String() string

String returns log level string representation.

type Logger

type Logger interface {
	Errorf(format string, v ...interface{})
	Warnf(format string, v ...interface{})
	Infof(format string, v ...interface{})
	Debugf(format string, v ...interface{})
}

Logger is common logging interface.

type Message

type Message struct {
	// MessageID is a user-settable identifier for the message used for request-reply patterns.
	MessageID string `json:"MessageId,omitempty"`

	// To is a destination specified in cloud-to-device messages.
	To string `json:"To,omitempty"`

	// ExpiryTime is time of message expiration.
	ExpiryTime *time.Time `json:"ExpiryTimeUtc,omitempty"`

	// EnqueuedTime is time the Cloud-to-Device message was received by IoT Hub.
	EnqueuedTime *time.Time `json:"EnqueuedTime,omitempty"`

	// CorrelationID is a string property in a response message that typically
	// contains the MessageId of the request, in request-reply patterns.
	CorrelationID string `json:"CorrelationId,omitempty"`

	// UserID is an ID used to specify the origin of messages.
	UserID string `json:"UserId,omitempty"`

	// ConnectionDeviceID is an ID set by IoT Hub on device-to-cloud messages.
	// It contains the deviceId of the device that sent the message.
	ConnectionDeviceID string `json:"ConnectionDeviceId,omitempty"`

	// ConnectionDeviceGenerationID is an ID set by IoT Hub on device-to-cloud messages.
	// It contains the generationId (as per Device identity properties)
	// of the device that sent the message.
	ConnectionDeviceGenerationID string `json:"ConnectionDeviceGenerationId,omitempty"`

	// ConnectionAuthMethod is an authentication method set by IoT Hub on
	// device-to-cloud messages. This property contains information about
	// the authentication method used to authenticate the device sending the message.
	ConnectionAuthMethod *ConnectionAuthMethod `json:"ConnectionAuthMethod,omitempty"`

	// MessageSource determines a device-to-cloud message transport.
	MessageSource string `json:"MessageSource,omitempty"`

	// Payload is message data.
	Payload []byte `json:"Payload,omitempty"`

	// Properties are custom message properties (property bags).
	Properties map[string]string `json:"Properties,omitempty"`

	// TransportOptions transport specific options.
	TransportOptions map[string]interface{} `json:"-"`
}

Message is a common message format for all device-facing protocols. This message format is used for both device-to-cloud and cloud-to-device messages. See: https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-messages-construct

type PrintFunc added in v0.1.0

type PrintFunc func(v ...interface{})

PrintFunc is used for writing logs that works as fmt.Print.

type SharedAccessKey added in v0.3.0

type SharedAccessKey struct {
	HostName            string
	SharedAccessKeyName string
	SharedAccessKey     string
}

SharedAccessKey is SAS token generator.

func NewSharedAccessKey added in v0.3.0

func NewSharedAccessKey(hostname, policy, key string) *SharedAccessKey

NewSharedAccessKey creates new shared access key for subsequent token generation.

func (*SharedAccessKey) Token added in v0.3.0

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

Token generates a shared access signature for the named resource and lifetime.

type SharedAccessSignature added in v0.3.0

type SharedAccessSignature struct {
	Sr  string
	Sig string
	Se  time.Time
	Skn string
}

SharedAccessSignature is a shared access signature instance.

func NewSharedAccessSignature added in v0.3.0

func NewSharedAccessSignature(
	resource, policy, key string, expiry time.Time,
) (*SharedAccessSignature, error)

NewSharedAccessSignature initialized a new shared access signature and generates signature fields based on the given input.

func (*SharedAccessSignature) String added in v0.3.0

func (sas *SharedAccessSignature) String() string

String converts the signature to a token string.

Jump to

Keyboard shortcuts

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