Documentation
¶
Index ¶
- Constants
- func NewCreateEntityHandler(ctxReg ContextRegistry) http.HandlerFunc
- func NewCreateEntityHandlerWithCallback(ctxReg ContextRegistry, logger zerolog.Logger, ...) http.HandlerFunc
- func NewQueryEntitiesHandler(ctxReg ContextRegistry) http.HandlerFunc
- func NewRegisterContextSourceHandler(ctxReg ContextRegistry) http.HandlerFunc
- func NewRetrieveEntityHandler(ctxReg ContextRegistry) http.HandlerFunc
- func NewUpdateEntityAttributesHandler(ctxReg ContextRegistry) http.HandlerFunc
- func NewUpdateEntityAttributesHandlerWithCallback(ctxReg ContextRegistry, logger zerolog.Logger, ...) http.HandlerFunc
- type ContextRegistry
- type ContextSource
- type ContextSourceMock
- func (mock *ContextSourceMock) CreateEntity(typeName string, entityID string, request Request) error
- func (mock *ContextSourceMock) CreateEntityCalls() []struct{ ... }
- func (mock *ContextSourceMock) GetEntities(query Query, callback QueryEntitiesCallback) error
- func (mock *ContextSourceMock) GetEntitiesCalls() []struct{ ... }
- func (mock *ContextSourceMock) GetProvidedTypeFromID(entityID string) (string, error)
- func (mock *ContextSourceMock) GetProvidedTypeFromIDCalls() []struct{ ... }
- func (mock *ContextSourceMock) ProvidesAttribute(attributeName string) bool
- func (mock *ContextSourceMock) ProvidesAttributeCalls() []struct{ ... }
- func (mock *ContextSourceMock) ProvidesEntitiesWithMatchingID(entityID string) bool
- func (mock *ContextSourceMock) ProvidesEntitiesWithMatchingIDCalls() []struct{ ... }
- func (mock *ContextSourceMock) ProvidesType(typeName string) bool
- func (mock *ContextSourceMock) ProvidesTypeCalls() []struct{ ... }
- func (mock *ContextSourceMock) RetrieveEntity(entityID string, request Request) (Entity, error)
- func (mock *ContextSourceMock) RetrieveEntityCalls() []struct{ ... }
- func (mock *ContextSourceMock) UpdateEntityAttributes(entityID string, request Request) error
- func (mock *ContextSourceMock) UpdateEntityAttributesCalls() []struct{ ... }
- type CreateEntityCompletionCallback
- type CsourceRegistration
- type Entity
- type GeoQuery
- type Query
- type QueryEntitiesCallback
- type Request
- type TemporalQuery
- type UpdateEntityAttributesCompletionCallback
Constants ¶
const ( //GeoSpatialRelationNearPoint describes a relation as a max or min distance from a Point GeoSpatialRelationNearPoint = "near" //GeoSpatialRelationWithinRect describes a relation as an overlapping polygon GeoSpatialRelationWithinRect = "within" //TemporalRelationAfterTime describes a relation where observedAt >= timeAt TemporalRelationAfterTime = "after" //TemporalRelationBeforeTime describes a relation where observedAt < timeAt TemporalRelationBeforeTime = "before" //TemporalRelationBetweenTimes describes a relation where timeAt <= observedAt < endTimeAt TemporalRelationBetweenTimes = "between" //TemporalRelationTimeProperty contains the temporal property to which the query can be applied TemporalRelationTimeProperty = "timeproperty" //QueryDefaultPaginationLimit defines the limit that should be used for GET operations //when the client does not supply a value QueryDefaultPaginationLimit = uint64(1000) )
Variables ¶
This section is empty.
Functions ¶
func NewCreateEntityHandler ¶
func NewCreateEntityHandler(ctxReg ContextRegistry) http.HandlerFunc
NewCreateEntityHandler handles incoming POST requests for NGSI entities
func NewCreateEntityHandlerWithCallback ¶
func NewCreateEntityHandlerWithCallback( ctxReg ContextRegistry, logger zerolog.Logger, onsuccess CreateEntityCompletionCallback) http.HandlerFunc
func NewQueryEntitiesHandler ¶
func NewQueryEntitiesHandler(ctxReg ContextRegistry) http.HandlerFunc
NewQueryEntitiesHandler handles GET requests for NGSI entities
func NewRegisterContextSourceHandler ¶
func NewRegisterContextSourceHandler(ctxReg ContextRegistry) http.HandlerFunc
NewRegisterContextSourceHandler handles POST requests for csource registrations
func NewRetrieveEntityHandler ¶
func NewRetrieveEntityHandler(ctxReg ContextRegistry) http.HandlerFunc
NewRetrieveEntityHandler retrieves entity by ID.
func NewUpdateEntityAttributesHandler ¶
func NewUpdateEntityAttributesHandler(ctxReg ContextRegistry) http.HandlerFunc
NewUpdateEntityAttributesHandler handles PATCH requests for NGSI entitity attributes
func NewUpdateEntityAttributesHandlerWithCallback ¶
func NewUpdateEntityAttributesHandlerWithCallback( ctxReg ContextRegistry, logger zerolog.Logger, onsuccess UpdateEntityAttributesCompletionCallback) http.HandlerFunc
NewUpdateEntityAttributesHandlerWithCallback handles PATCH requests for NGSI entitity attributes and calls a callback on successful completion
Types ¶
type ContextRegistry ¶
type ContextRegistry interface { GetContextSourcesForQuery(query Query) []ContextSource GetContextSourcesForEntity(entityID string) []ContextSource GetContextSourcesForEntityType(entityType string) []ContextSource Register(source ContextSource) }
ContextRegistry is where Context Sources register the information that they can provide
func NewContextRegistry ¶
func NewContextRegistry() ContextRegistry
NewContextRegistry initializes and returns a new default context registry without any registered context sources
type ContextSource ¶
type ContextSource interface { ProvidesAttribute(attributeName string) bool ProvidesEntitiesWithMatchingID(entityID string) bool GetProvidedTypeFromID(entityID string) (string, error) ProvidesType(typeName string) bool CreateEntity(typeName, entityID string, request Request) error GetEntities(query Query, callback QueryEntitiesCallback) error RetrieveEntity(entityID string, request Request) (Entity, error) UpdateEntityAttributes(entityID string, request Request) error }
ContextSource provides query and subscription support for a set of entities
func NewRemoteContextSource ¶
func NewRemoteContextSource(registration CsourceRegistration) (ContextSource, error)
NewRemoteContextSource creates an instance of a ContextSource by wrapping a CsourceRegistration
type ContextSourceMock ¶
type ContextSourceMock struct { // CreateEntityFunc mocks the CreateEntity method. CreateEntityFunc func(typeName string, entityID string, request Request) error // GetEntitiesFunc mocks the GetEntities method. GetEntitiesFunc func(query Query, callback QueryEntitiesCallback) error // GetProvidedTypeFromIDFunc mocks the GetProvidedTypeFromID method. GetProvidedTypeFromIDFunc func(entityID string) (string, error) // ProvidesAttributeFunc mocks the ProvidesAttribute method. ProvidesAttributeFunc func(attributeName string) bool // ProvidesEntitiesWithMatchingIDFunc mocks the ProvidesEntitiesWithMatchingID method. ProvidesEntitiesWithMatchingIDFunc func(entityID string) bool // ProvidesTypeFunc mocks the ProvidesType method. ProvidesTypeFunc func(typeName string) bool // RetrieveEntityFunc mocks the RetrieveEntity method. RetrieveEntityFunc func(entityID string, request Request) (Entity, error) // UpdateEntityAttributesFunc mocks the UpdateEntityAttributes method. UpdateEntityAttributesFunc func(entityID string, request Request) error // contains filtered or unexported fields }
ContextSourceMock is a mock implementation of ContextSource.
func TestSomethingThatUsesContextSource(t *testing.T) { // make and configure a mocked ContextSource mockedContextSource := &ContextSourceMock{ CreateEntityFunc: func(typeName string, entityID string, request Request) error { panic("mock out the CreateEntity method") }, GetEntitiesFunc: func(query Query, callback QueryEntitiesCallback) error { panic("mock out the GetEntities method") }, GetProvidedTypeFromIDFunc: func(entityID string) (string, error) { panic("mock out the GetProvidedTypeFromID method") }, ProvidesAttributeFunc: func(attributeName string) bool { panic("mock out the ProvidesAttribute method") }, ProvidesEntitiesWithMatchingIDFunc: func(entityID string) bool { panic("mock out the ProvidesEntitiesWithMatchingID method") }, ProvidesTypeFunc: func(typeName string) bool { panic("mock out the ProvidesType method") }, RetrieveEntityFunc: func(entityID string, request Request) (Entity, error) { panic("mock out the RetrieveEntity method") }, UpdateEntityAttributesFunc: func(entityID string, request Request) error { panic("mock out the UpdateEntityAttributes method") }, } // use mockedContextSource in code that requires ContextSource // and then make assertions. }
func (*ContextSourceMock) CreateEntity ¶
func (mock *ContextSourceMock) CreateEntity(typeName string, entityID string, request Request) error
CreateEntity calls CreateEntityFunc.
func (*ContextSourceMock) CreateEntityCalls ¶
func (mock *ContextSourceMock) CreateEntityCalls() []struct { TypeName string EntityID string Request Request }
CreateEntityCalls gets all the calls that were made to CreateEntity. Check the length with:
len(mockedContextSource.CreateEntityCalls())
func (*ContextSourceMock) GetEntities ¶
func (mock *ContextSourceMock) GetEntities(query Query, callback QueryEntitiesCallback) error
GetEntities calls GetEntitiesFunc.
func (*ContextSourceMock) GetEntitiesCalls ¶
func (mock *ContextSourceMock) GetEntitiesCalls() []struct { Query Query Callback QueryEntitiesCallback }
GetEntitiesCalls gets all the calls that were made to GetEntities. Check the length with:
len(mockedContextSource.GetEntitiesCalls())
func (*ContextSourceMock) GetProvidedTypeFromID ¶
func (mock *ContextSourceMock) GetProvidedTypeFromID(entityID string) (string, error)
GetProvidedTypeFromID calls GetProvidedTypeFromIDFunc.
func (*ContextSourceMock) GetProvidedTypeFromIDCalls ¶
func (mock *ContextSourceMock) GetProvidedTypeFromIDCalls() []struct { EntityID string }
GetProvidedTypeFromIDCalls gets all the calls that were made to GetProvidedTypeFromID. Check the length with:
len(mockedContextSource.GetProvidedTypeFromIDCalls())
func (*ContextSourceMock) ProvidesAttribute ¶
func (mock *ContextSourceMock) ProvidesAttribute(attributeName string) bool
ProvidesAttribute calls ProvidesAttributeFunc.
func (*ContextSourceMock) ProvidesAttributeCalls ¶
func (mock *ContextSourceMock) ProvidesAttributeCalls() []struct { AttributeName string }
ProvidesAttributeCalls gets all the calls that were made to ProvidesAttribute. Check the length with:
len(mockedContextSource.ProvidesAttributeCalls())
func (*ContextSourceMock) ProvidesEntitiesWithMatchingID ¶
func (mock *ContextSourceMock) ProvidesEntitiesWithMatchingID(entityID string) bool
ProvidesEntitiesWithMatchingID calls ProvidesEntitiesWithMatchingIDFunc.
func (*ContextSourceMock) ProvidesEntitiesWithMatchingIDCalls ¶
func (mock *ContextSourceMock) ProvidesEntitiesWithMatchingIDCalls() []struct { EntityID string }
ProvidesEntitiesWithMatchingIDCalls gets all the calls that were made to ProvidesEntitiesWithMatchingID. Check the length with:
len(mockedContextSource.ProvidesEntitiesWithMatchingIDCalls())
func (*ContextSourceMock) ProvidesType ¶
func (mock *ContextSourceMock) ProvidesType(typeName string) bool
ProvidesType calls ProvidesTypeFunc.
func (*ContextSourceMock) ProvidesTypeCalls ¶
func (mock *ContextSourceMock) ProvidesTypeCalls() []struct { TypeName string }
ProvidesTypeCalls gets all the calls that were made to ProvidesType. Check the length with:
len(mockedContextSource.ProvidesTypeCalls())
func (*ContextSourceMock) RetrieveEntity ¶
func (mock *ContextSourceMock) RetrieveEntity(entityID string, request Request) (Entity, error)
RetrieveEntity calls RetrieveEntityFunc.
func (*ContextSourceMock) RetrieveEntityCalls ¶
func (mock *ContextSourceMock) RetrieveEntityCalls() []struct { EntityID string Request Request }
RetrieveEntityCalls gets all the calls that were made to RetrieveEntity. Check the length with:
len(mockedContextSource.RetrieveEntityCalls())
func (*ContextSourceMock) UpdateEntityAttributes ¶
func (mock *ContextSourceMock) UpdateEntityAttributes(entityID string, request Request) error
UpdateEntityAttributes calls UpdateEntityAttributesFunc.
func (*ContextSourceMock) UpdateEntityAttributesCalls ¶
func (mock *ContextSourceMock) UpdateEntityAttributesCalls() []struct { EntityID string Request Request }
UpdateEntityAttributesCalls gets all the calls that were made to UpdateEntityAttributes. Check the length with:
len(mockedContextSource.UpdateEntityAttributesCalls())
type CsourceRegistration ¶
type CsourceRegistration interface { Endpoint() string GetProvidedTypeFromID(entityID string) (string, error) ProvidesAttribute(attributeName string) bool ProvidesEntitiesWithMatchingID(entityID string) bool ProvidesType(typeName string) bool }
CsourceRegistration is a wrapper for information about a registered context source
func NewCsourceRegistration ¶
func NewCsourceRegistration(entityTypeName string, attributeNames []string, endpoint string, idpattern *string) (CsourceRegistration, error)
NewCsourceRegistration creates and returns a concrete implementation of the CsourceRegistration interface
func NewCsourceRegistrationFromJSON ¶
func NewCsourceRegistrationFromJSON(jsonBytes []byte) (CsourceRegistration, error)
NewCsourceRegistrationFromJSON unpacks a byte buffer into a CsourceRegistration and validates its contents
type Entity ¶
type Entity interface { }
Entity is an informational representative of something that is supposed to exist in the real world, physically or conceptually
type GeoQuery ¶
type GeoQuery struct { Geometry string `json:"geometry"` Coordinates []float64 `json:"coordinates"` GeoRel string `json:"georel"` GeoProperty *string `json:"geoproperty,omitempty"` // contains filtered or unexported fields }
GeoQuery contains information about a geo-query that may be used for subscriptions or when querying entities
func (*GeoQuery) Distance ¶
Distance returns the required distance in meters from a near Point and a boolean flag indicating if it is inclusive or exclusive
type Query ¶
type Query interface { HasDeviceReference() bool Device() string PaginationLimit() uint64 PaginationOffset() uint64 IsGeoQuery() bool Geo() GeoQuery IsTemporalQuery() bool Temporal() TemporalQuery EntityAttributes() []string EntityTypes() []string Request() *http.Request }
Query is an interface to be used when passing queries to context registries and sources
type QueryEntitiesCallback ¶
QueryEntitiesCallback is used when queried context sources should pass back any entities matching the query that has been passed in
type Request ¶
type Request interface { BodyReader() io.Reader DecodeBodyInto(v interface{}) error Request() *http.Request }
Request is an interface to be used when passing header and body information for NGSI-LD API requests
type TemporalQuery ¶
type TemporalQuery struct {
// contains filtered or unexported fields
}
func (TemporalQuery) Property ¶
func (tq TemporalQuery) Property() string