application

package
v0.0.0-...-b64cb9f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 25, 2026 License: AGPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

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

type Pagination struct {
	Limit  int
	Offset int
	Export bool
}

func DefaultPagination

func DefaultPagination() Pagination

type QueryResult

type QueryResult struct {
	Data       [][]byte
	Count      int
	Limit      int
	Offset     int
	TotalCount int64
}

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
}

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) GetTags

func (mock *ThingsReaderMock) GetTags(ctx context.Context, tenants []string) ([]string, error)

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 ThingsWriter interface {
	AddThing(ctx context.Context, t things.Thing) error
	UpdateThing(ctx context.Context, t things.Thing) error
	DeleteThing(ctx context.Context, thingID string) error
	AddValue(ctx context.Context, t things.Thing, m things.Value) error
}

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) AddThing

func (mock *ThingsWriterMock) AddThing(ctx context.Context, t things.Thing) error

AddThing calls AddThingFunc.

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) AddValue

func (mock *ThingsWriterMock) AddValue(ctx context.Context, t things.Thing, m things.Value) error

AddValue calls AddValueFunc.

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

func (mock *ThingsWriterMock) UpdateThing(ctx context.Context, t things.Thing) error

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"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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