Documentation
¶
Overview ¶
Package things contains the domain concept definitions needed to support Mainflux things service functionality.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrMalformedEntity indicates malformed entity specification (e.g. // invalid username or password). ErrMalformedEntity = errors.New("malformed entity specification") // when accessing a protected resource. ErrUnauthorizedAccess = errors.New("missing or invalid credentials provided") // ErrNotFound indicates a non-existent entity request. ErrNotFound = errors.New("non-existent entity") )
Functions ¶
This section is empty.
Types ¶
type Channel ¶
Channel represents a Mainflux "communication group". This group contains the things that can exchange messages between eachother.
type ChannelCache ¶
type ChannelCache interface {
// Connect channel thing connection.
Connect(string, string) error
// HasThing checks if thing is connected to channel.
HasThing(string, string) bool
// Disconnects thing from channel.
Disconnect(string, string) error
// Removes channel from cache.
Remove(string) error
}
ChannelCache contains channel-thing connection caching interface.
type ChannelRepository ¶
type ChannelRepository interface {
// Save persists the channel. Successful operation is indicated by unique
// identifier accompanied by nil error response. A non-nil error is
// returned to indicate operation failure.
Save(Channel) (string, error)
// Update performs an update to the existing channel. A non-nil error is
// returned to indicate operation failure.
Update(Channel) error
// RetrieveByID retrieves the channel having the provided identifier, that is owned
// by the specified user.
RetrieveByID(string, string) (Channel, error)
// RetrieveAll retrieves the subset of channels owned by the specified user.
RetrieveAll(string, uint64, uint64) ChannelsPage
// RetrieveByThing retrieves the subset of channels owned by the specified
// user and have specified thing connected to them.
RetrieveByThing(string, string, uint64, uint64) ChannelsPage
// Remove removes the channel having the provided identifier, that is owned
// by the specified user.
Remove(string, string) error
// Connect adds thing to the channel's list of connected things.
Connect(string, string, string) error
// Disconnect removes thing from the channel's list of connected
// things.
Disconnect(string, string, string) error
// HasThing determines whether the thing with the provided access key, is
// "connected" to the specified channel. If that's the case, it returns
// thing's ID.
HasThing(string, string) (string, error)
}
ChannelRepository specifies a channel persistence API.
type ChannelsPage ¶
type ChannelsPage struct {
PageMetadata
Channels []Channel
}
ChannelsPage contains page related metadata as well as list of channels that belong to this page.
type IdentityProvider ¶
type IdentityProvider interface {
// ID generates the unique identifier.
ID() string
}
IdentityProvider specifies an API for generating unique identifiers.
type PageMetadata ¶
PageMetadata contains page metadata that helps navigation.
type Service ¶
type Service interface {
// AddThing adds new thing to the user identified by the provided key.
AddThing(string, Thing) (Thing, error)
// UpdateThing updates the thing identified by the provided ID, that
// belongs to the user identified by the provided key.
UpdateThing(string, Thing) error
// ViewThing retrieves data about the thing identified with the provided
// ID, that belongs to the user identified by the provided key.
ViewThing(string, string) (Thing, error)
// ListThings retrieves data about subset of things that belongs to the
// user identified by the provided key.
ListThings(string, uint64, uint64) (ThingsPage, error)
// ListThingsByChannel retrieves data about subset of things that are
// connected to specified channel and belong to the user identified by
// the provided key.
ListThingsByChannel(string, string, uint64, uint64) (ThingsPage, error)
// RemoveThing removes the thing identified with the provided ID, that
// belongs to the user identified by the provided key.
RemoveThing(string, string) error
// CreateChannel adds new channel to the user identified by the provided key.
CreateChannel(string, Channel) (Channel, error)
// UpdateChannel updates the channel identified by the provided ID, that
// belongs to the user identified by the provided key.
UpdateChannel(string, Channel) error
// ViewChannel retrieves data about the channel identified by the provided
// ID, that belongs to the user identified by the provided key.
ViewChannel(string, string) (Channel, error)
// ListChannels retrieves data about subset of channels that belongs to the
// user identified by the provided key.
ListChannels(string, uint64, uint64) (ChannelsPage, error)
// ListChannelsByThing retrieves data about subset of channels that have
// specified thing connected to them and belong to the user identified by
// the provided key.
ListChannelsByThing(string, string, uint64, uint64) (ChannelsPage, error)
// RemoveChannel removes the thing identified by the provided ID, that
// belongs to the user identified by the provided key.
RemoveChannel(string, string) error
// Connect adds thing to the channel's list of connected things.
Connect(string, string, string) error
// Disconnect removes thing from the channel's list of connected
// things.
Disconnect(string, string, string) error
// CanAccess determines whether the channel can be accessed using the
// provided key and returns thing's id if access is allowed.
CanAccess(string, string) (string, error)
// Identify returns thing ID for given thing key.
Identify(string) (string, error)
}
Service specifies an API that must be fullfiled by the domain service implementation, and all of its decorators (e.g. logging & metrics).
func New ¶
func New(users mainflux.UsersServiceClient, things ThingRepository, channels ChannelRepository, ccache ChannelCache, tcache ThingCache, idp IdentityProvider) Service
New instantiates the things service implementation.
type Thing ¶
Thing represents a Mainflux thing. Each thing is owned by one user, and it is assigned with the unique identifier and (temporary) access key.
type ThingCache ¶
type ThingCache interface {
// Save stores pair thing key, thing id.
Save(string, string) error
// ID returns thing ID for given key.
ID(string) (string, error)
// Removes thing from cache.
Remove(string) error
}
ThingCache contains thing caching interface.
type ThingRepository ¶
type ThingRepository interface {
// Save persists the thing. Successful operation is indicated by non-nil
// error response.
Save(Thing) (string, error)
// Update performs an update to the existing thing. A non-nil error is
// returned to indicate operation failure.
Update(Thing) error
// RetrieveByID retrieves the thing having the provided identifier, that is owned
// by the specified user.
RetrieveByID(string, string) (Thing, error)
// RetrieveByKey returns thing ID for given thing key.
RetrieveByKey(string) (string, error)
// RetrieveAll retrieves the subset of things owned by the specified user.
RetrieveAll(string, uint64, uint64) ThingsPage
// RetrieveByChannel retrieves the subset of things owned by the specified
// user and connected to specified channel.
RetrieveByChannel(string, string, uint64, uint64) ThingsPage
// Remove removes the thing having the provided identifier, that is owned
// by the specified user.
Remove(string, string) error
}
ThingRepository specifies a thing persistence API.
type ThingsPage ¶
type ThingsPage struct {
PageMetadata
Things []Thing
}
ThingsPage contains page related metadata as well as list of things that belong to this page.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package api contains API-related concerns: endpoint definitions, middlewares and all resource representations.
|
Package api contains API-related concerns: endpoint definitions, middlewares and all resource representations. |
|
grpc
Package grpc contains implementation of things service gRPC API.
|
Package grpc contains implementation of things service gRPC API. |
|
http
Package http contains implementation of things service HTTP API.
|
Package http contains implementation of things service HTTP API. |
|
Package postgres contains repository implementations using PostgreSQL as the underlying database.
|
Package postgres contains repository implementations using PostgreSQL as the underlying database. |
|
Package redis contains cache implementations using Redis as the underlying database.
|
Package redis contains cache implementations using Redis as the underlying database. |
|
Package uuid provides a UUID identity provider.
|
Package uuid provides a UUID identity provider. |