1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-05-02 22:17:10 +08:00
Aleksandar Novaković 5799356b14 MF-549 - Change metadata format from JSON string to JSON object (#706)
* Update metadata type in things service

Update things service so that metadata has map type. Update repo
implementation by adding sqlx lib.

Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>

* Add sqlx lib to bootstrap service

Add sqlx lib to bootstrap service and update metadata field type.

Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>

* Update metadata in redis streams consumer

Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>

* Update tests for bootstrap service

Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>

* Fix mongo reader logging and driver version

Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>

* Fix mongo reader and writer

Fix mongo reader and writer by updating driver version.

Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>

* Update SDK with new metadata format

Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>

* Update LoRa adapter with new metadata format

Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>

* Update users service in order to use sqlx

Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>

* Replace anonymous struct with map

Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>

* Update docs for LoRa adapter

Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>

* Fix LoRa application metadata format

Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>

* Fix metadata format in LoRa docs

Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>

* Add metadata2 var to SDK things test

Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
2019-04-16 14:58:56 +02:00

84 lines
2.1 KiB
Go

//
// Copyright (c) 2018
// Mainflux
//
// SPDX-License-Identifier: Apache-2.0
//
package things
import "strings"
// 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 Thing struct {
ID string
Owner string
Type string
Name string
Key string
Metadata map[string]interface{}
}
// ThingsPage contains page related metadata as well as list of things that
// belong to this page.
type ThingsPage struct {
PageMetadata
Things []Thing
}
var thingTypes = map[string]bool{
"app": true,
"device": true,
}
// Validate returns an error if thing representation is invalid.
func (c *Thing) Validate() error {
if c.Type = strings.ToLower(c.Type); !thingTypes[c.Type] {
return ErrMalformedEntity
}
return nil
}
// ThingRepository specifies a thing persistence API.
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
}
// ThingCache contains thing caching interface.
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
}