Documentation
¶
Index ¶
- Constants
- Variables
- func NewMeasurementsHandler(app ThingsApp, msgCtx messaging.MsgContext) messaging.TopicMessageHandler
- type CompareOperator
- type NumericFieldFilter
- type NumericValueFilter
- type Pagination
- type QueryResult
- type ThingQuery
- type ThingsApp
- type ThingsReader
- type ThingsReaderMock
- func (mock *ThingsReaderMock) GetTags(ctx context.Context, tenants []string) ([]string, error)
- func (mock *ThingsReaderMock) GetTagsCalls() []struct{ ... }
- func (mock *ThingsReaderMock) QueryThings(ctx context.Context, query ThingQuery) (QueryResult, error)
- func (mock *ThingsReaderMock) QueryThingsCalls() []struct{ ... }
- func (mock *ThingsReaderMock) QueryValues(ctx context.Context, query ValueQuery) (QueryResult, error)
- func (mock *ThingsReaderMock) QueryValuesCalls() []struct{ ... }
- type ThingsWriter
- type ThingsWriterMock
- func (mock *ThingsWriterMock) AddThing(ctx context.Context, t things.Thing) error
- func (mock *ThingsWriterMock) AddThingCalls() []struct{ ... }
- func (mock *ThingsWriterMock) AddValue(ctx context.Context, t things.Thing, m things.Value) error
- func (mock *ThingsWriterMock) AddValueCalls() []struct{ ... }
- func (mock *ThingsWriterMock) DeleteThing(ctx context.Context, thingID string) error
- func (mock *ThingsWriterMock) DeleteThingCalls() []struct{ ... }
- func (mock *ThingsWriterMock) UpdateThing(ctx context.Context, t things.Thing) error
- func (mock *ThingsWriterMock) UpdateThingCalls() []struct{ ... }
- type TimeFilter
- type TimeRelation
- type ValueQuery
- type ValueQueryMode
Constants ¶
View Source
const DefaultQueryLimit = 100
Variables ¶
View Source
var ( ErrThingNotFound = errors.New("thing not found") ErrAlreadyExists = errors.New("thing already exists") ErrMissingThingID = errors.New("thing ID must be provided") ErrMissingThingTenant = errors.New("tenant must be provided") ErrMissingThingType = errors.New("thing type must be provided") )
Functions ¶
func NewMeasurementsHandler ¶
func NewMeasurementsHandler(app ThingsApp, msgCtx messaging.MsgContext) messaging.TopicMessageHandler
Types ¶
type CompareOperator ¶
type CompareOperator string
const ( CompareEqual CompareOperator = "eq" CompareNotEqual CompareOperator = "ne" CompareGreaterThan CompareOperator = "gt" CompareLessThan CompareOperator = "lt" )
type NumericFieldFilter ¶
type NumericFieldFilter struct {
Field string
Op CompareOperator
Value float64
}
type NumericValueFilter ¶
type NumericValueFilter struct {
Op CompareOperator
Value float64
}
type Pagination ¶
func DefaultPagination ¶
func DefaultPagination() Pagination
type QueryResult ¶
type ThingQuery ¶
type ThingQuery struct {
ID *string
Tenants []string
Types []string
SubType *string
Tags []string
RefDeviceID *string
NumericFilters []NumericFieldFilter
Page Pagination
}
func NewThingQuery ¶
func NewThingQuery() ThingQuery
func ThingByIDQuery ¶
func ThingByIDQuery(id string, tenants []string) ThingQuery
func ThingsByRefDeviceQuery ¶
func ThingsByRefDeviceQuery(deviceID string) ThingQuery
type ThingsApp ¶
type ThingsApp interface {
HandleMeasurements(ctx context.Context, measurements []things.Measurement)
Add(ctx context.Context, b []byte) error
Delete(ctx context.Context, thingID string, tenants []string) error
Merge(ctx context.Context, thingID string, b []byte, tenants []string) error
Query(ctx context.Context, query ThingQuery) (QueryResult, error)
Update(ctx context.Context, b []byte, tenants []string) error
AddValue(ctx context.Context, t things.Thing, m things.Value) error
Values(ctx context.Context, query ValueQuery) (QueryResult, error)
Tags(ctx context.Context, tenants []string) ([]string, error)
Types(ctx context.Context, tenants []string) ([]things.ThingType, error)
LoadConfig(ctx context.Context, r io.Reader) error
Seed(ctx context.Context, r io.Reader) error
}
func New ¶
func New(ctx context.Context, r ThingsReader, w ThingsWriter, msgCtx messaging.MsgContext) ThingsApp
type ThingsReader ¶
type ThingsReader interface {
QueryThings(ctx context.Context, query ThingQuery) (QueryResult, error)
QueryValues(ctx context.Context, query ValueQuery) (QueryResult, error)
GetTags(ctx context.Context, tenants []string) ([]string, error)
}
type ThingsReaderMock ¶
type ThingsReaderMock struct {
GetTagsFunc func(ctx context.Context, tenants []string) ([]string, error)
QueryThingsFunc func(ctx context.Context, query ThingQuery) (QueryResult, error)
QueryValuesFunc func(ctx context.Context, query ValueQuery) (QueryResult, error)
// contains filtered or unexported fields
}
func (*ThingsReaderMock) GetTagsCalls ¶
func (mock *ThingsReaderMock) GetTagsCalls() []struct { Ctx context.Context Tenants []string }
func (*ThingsReaderMock) QueryThings ¶
func (mock *ThingsReaderMock) QueryThings(ctx context.Context, query ThingQuery) (QueryResult, error)
func (*ThingsReaderMock) QueryThingsCalls ¶
func (mock *ThingsReaderMock) QueryThingsCalls() []struct { Ctx context.Context Query ThingQuery }
func (*ThingsReaderMock) QueryValues ¶
func (mock *ThingsReaderMock) QueryValues(ctx context.Context, query ValueQuery) (QueryResult, error)
func (*ThingsReaderMock) QueryValuesCalls ¶
func (mock *ThingsReaderMock) QueryValuesCalls() []struct { Ctx context.Context Query ValueQuery }
type ThingsWriter ¶
type ThingsWriterMock ¶
type ThingsWriterMock struct {
// AddThingFunc mocks the AddThing method.
AddThingFunc func(ctx context.Context, t things.Thing) error
// AddValueFunc mocks the AddValue method.
AddValueFunc func(ctx context.Context, t things.Thing, m things.Value) error
// DeleteThingFunc mocks the DeleteThing method.
DeleteThingFunc func(ctx context.Context, thingID string) error
// UpdateThingFunc mocks the UpdateThing method.
UpdateThingFunc func(ctx context.Context, t things.Thing) error
// contains filtered or unexported fields
}
ThingsWriterMock is a mock implementation of ThingsWriter.
func TestSomethingThatUsesThingsWriter(t *testing.T) {
// make and configure a mocked ThingsWriter
mockedThingsWriter := &ThingsWriterMock{
AddThingFunc: func(ctx context.Context, t things.Thing) error {
panic("mock out the AddThing method")
},
AddValueFunc: func(ctx context.Context, t things.Thing, m things.Value) error {
panic("mock out the AddValue method")
},
DeleteThingFunc: func(ctx context.Context, thingID string) error {
panic("mock out the DeleteThing method")
},
UpdateThingFunc: func(ctx context.Context, t things.Thing) error {
panic("mock out the UpdateThing method")
},
}
// use mockedThingsWriter in code that requires ThingsWriter
// and then make assertions.
}
func (*ThingsWriterMock) AddThingCalls ¶
func (mock *ThingsWriterMock) AddThingCalls() []struct { Ctx context.Context T things.Thing }
AddThingCalls gets all the calls that were made to AddThing. Check the length with:
len(mockedThingsWriter.AddThingCalls())
func (*ThingsWriterMock) AddValueCalls ¶
func (mock *ThingsWriterMock) AddValueCalls() []struct { Ctx context.Context T things.Thing M things.Value }
AddValueCalls gets all the calls that were made to AddValue. Check the length with:
len(mockedThingsWriter.AddValueCalls())
func (*ThingsWriterMock) DeleteThing ¶
func (mock *ThingsWriterMock) DeleteThing(ctx context.Context, thingID string) error
DeleteThing calls DeleteThingFunc.
func (*ThingsWriterMock) DeleteThingCalls ¶
func (mock *ThingsWriterMock) DeleteThingCalls() []struct { Ctx context.Context ThingID string }
DeleteThingCalls gets all the calls that were made to DeleteThing. Check the length with:
len(mockedThingsWriter.DeleteThingCalls())
func (*ThingsWriterMock) UpdateThing ¶
UpdateThing calls UpdateThingFunc.
func (*ThingsWriterMock) UpdateThingCalls ¶
func (mock *ThingsWriterMock) UpdateThingCalls() []struct { Ctx context.Context T things.Thing }
UpdateThingCalls gets all the calls that were made to UpdateThing. Check the length with:
len(mockedThingsWriter.UpdateThingCalls())
type TimeFilter ¶
type TimeFilter struct {
Relation TimeRelation
At time.Time
EndAt *time.Time
}
type TimeRelation ¶
type TimeRelation string
const ( TimeBefore TimeRelation = "before" TimeAfter TimeRelation = "after" TimeBetween TimeRelation = "between" )
type ValueQuery ¶
type ValueQuery struct {
Mode ValueQueryMode
ID *string
ThingID *string
URNs []string
Time *TimeFilter
Value *NumericValueFilter
BoolValue *bool
RefDeviceID *string
ValueName *string
TimeUnit *string
DistinctBy *string
Page Pagination
}
func NewValueQuery ¶
func NewValueQuery() ValueQuery
type ValueQueryMode ¶
type ValueQueryMode string
const ( ValueQueryModeDefault ValueQueryMode = "default" ValueQueryModeLatest ValueQueryMode = "latest" ValueQueryModeDistinct ValueQueryMode = "distinct" ValueQueryModeCountByTime ValueQueryMode = "count_by_time" )
Click to show internal directories.
Click to hide internal directories.