model

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DateCreatedAttributeName  string = "dateCreated"
	DateModifiedAttributeName string = "dateModified"
	DateExpiresAttributeName  string = "dateExpires"
)
View Source
const (
	InvalidChars      string = `<>"'=;()`
	InvalidFieldChars string = `&?/#` // plus control characters and whitespaces
)

Variables

View Source
var ReservedAttrNames = [...]string{"id", "type", "geo:distance", "dateCreated", "dateModified"}

Functions

func IsValidAttributeName

func IsValidAttributeName(name string) bool

IsValidAttributeName checks whether the attribute name is valid or is forbidden. See: https://orioncontextbroker.docs.apiary.io/#introduction/specification/attribute-names-restrictions

func IsValidFieldSyntax

func IsValidFieldSyntax(str string) bool

IsValidFieldSyntax checks whether the field syntax is valid or violates restrictions. See: https://orioncontextbroker.docs.apiary.io/#introduction/specification/field-syntax-restrictions

func IsValidString

func IsValidString(str string) bool

IsValidString checks whether the string is valid or contains any forbidden character. See: https://github.com/telefonicaid/fiware-orion/blob/master/doc/manuals/user/forbidden_characters.md

func SanitizeString

func SanitizeString(str string) string

SanitizeString removes any forbidden character from a string.

Types

type APIResources

type APIResources struct {
	EntitiesUrl      string `json:"entities_url"`
	TypesUrl         string `json:"types_url"`
	SubscriptionsUrl string `json:"subscriptions_url"`
	RegistrationsUrl string `json:"registrations_url"`
}

type ActionType

type ActionType string
const (
	AppendAction       ActionType = "append"
	AppendStrictAction ActionType = "appendStrict"
	UpdateAction       ActionType = "update"
	DeleteAction       ActionType = "delete"
	ReplaceAction      ActionType = "replace"
)

type Attribute

type Attribute struct {
	Metadata map[string]*Metadata `json:"metadata,omitempty"`
	// contains filtered or unexported fields
}

Attribute is a Context attribute, i.e. a property of a context entity.

func (*Attribute) GetAsBoolean added in v0.3.3

func (a *Attribute) GetAsBoolean() (bool, error)

func (*Attribute) GetAsDateTime

func (a *Attribute) GetAsDateTime() (time.Time, error)

func (*Attribute) GetAsFloat

func (a *Attribute) GetAsFloat() (float64, error)

func (*Attribute) GetAsGeoJSON added in v0.5.0

func (a *Attribute) GetAsGeoJSON() (*geojson.Geometry, error)

func (*Attribute) GetAsGeoPoint

func (a *Attribute) GetAsGeoPoint() (*GeoPoint, error)

func (*Attribute) GetAsInteger

func (a *Attribute) GetAsInteger() (int, error)

func (*Attribute) GetAsString

func (a *Attribute) GetAsString() (string, error)

type AttributeType

type AttributeType string
const (
	StringType     AttributeType = "String"
	TextType       AttributeType = "Text"
	NumberType     AttributeType = "Number"
	FloatType      AttributeType = "Float"
	IntegerType    AttributeType = "Integer"
	BooleanType    AttributeType = "Boolean"
	PercentageType AttributeType = "Percentage"
	DateTimeType   AttributeType = "DateTime"
	GeoPointType   AttributeType = "geo:point"
	GeoLineType    AttributeType = "geo:line"
	GeoPolygonType AttributeType = "geo:polygon"
	GeoBoxType     AttributeType = "geo:box"
	GeoJSONType    AttributeType = "geo:json"
)

type BatchQuery added in v0.4.2

type BatchQuery struct {
	Entities   []*EntityMatcher `json:"entities,omitempty"`
	Attrs      []string         `json:"attrs,omitempty"`
	Expression *QueryExpression `json:"expression,omitempty"`
	Metadata   []string         `json:"metadata,omitempty"`
}

func (*BatchQuery) Match added in v0.4.2

func (batchQuery *BatchQuery) Match(matchers ...*EntityMatcher) error

type BatchUpdate

type BatchUpdate struct {
	ActionType ActionType `json:"actionType"`
	Entities   []*Entity  `json:"entities"`
}

func NewBatchUpdate

func NewBatchUpdate(action ActionType) *BatchUpdate

func (*BatchUpdate) AddEntity

func (u *BatchUpdate) AddEntity(entity *Entity)

type Entity

type Entity struct {
	Id         string                `json:"id"`
	Type       string                `json:"type,omitempty"`
	Attributes map[string]*Attribute `json:"-"`
}

Entity is a context entity, i.e. a thing in the NGSI model.

func NewEntity

func NewEntity(id string, entityType string) (*Entity, error)

Creates a new context entity with id and type and no attributes.

func (*Entity) GetAttribute

func (e *Entity) GetAttribute(name string) (*Attribute, error)

func (*Entity) GetAttributeAsBoolean added in v0.3.3

func (e *Entity) GetAttributeAsBoolean(attributeName string) (bool, error)

func (*Entity) GetAttributeAsDateTime added in v0.2.3

func (e *Entity) GetAttributeAsDateTime(attributeName string) (time.Time, error)

func (*Entity) GetAttributeAsFloat added in v0.2.3

func (e *Entity) GetAttributeAsFloat(attributeName string) (float64, error)

func (*Entity) GetAttributeAsGeoJSON added in v0.5.0

func (e *Entity) GetAttributeAsGeoJSON(attributeName string) (*geojson.Geometry, error)

func (*Entity) GetAttributeAsGeoPoint added in v0.2.3

func (e *Entity) GetAttributeAsGeoPoint(attributeName string) (*GeoPoint, error)

func (*Entity) GetAttributeAsInteger added in v0.2.3

func (e *Entity) GetAttributeAsInteger(attributeName string) (int, error)

func (*Entity) GetAttributeAsString added in v0.2.3

func (e *Entity) GetAttributeAsString(attributeName string) (string, error)

func (*Entity) GetDateCreated added in v0.2.4

func (e *Entity) GetDateCreated() (time.Time, error)

func (*Entity) GetDateExpires added in v0.2.4

func (e *Entity) GetDateExpires() (time.Time, error)

func (*Entity) GetDateModified added in v0.2.4

func (e *Entity) GetDateModified() (time.Time, error)

func (*Entity) MarshalJSON

func (e *Entity) MarshalJSON() ([]byte, error)

func (*Entity) SetAttribute

func (e *Entity) SetAttribute(name string, typ AttributeType, value interface{}) error

func (*Entity) SetAttributeAsBoolean added in v0.3.3

func (e *Entity) SetAttributeAsBoolean(name string, value bool) error

func (*Entity) SetAttributeAsDateTime

func (e *Entity) SetAttributeAsDateTime(name string, value time.Time) error

func (*Entity) SetAttributeAsFloat

func (e *Entity) SetAttributeAsFloat(name string, value float64) error

func (*Entity) SetAttributeAsGeoJSON added in v0.5.0

func (e *Entity) SetAttributeAsGeoJSON(name string, value *geojson.Geometry) error

func (*Entity) SetAttributeAsGeoPoint

func (e *Entity) SetAttributeAsGeoPoint(name string, value *GeoPoint) error

func (*Entity) SetAttributeAsInteger

func (e *Entity) SetAttributeAsInteger(name string, value int) error

func (*Entity) SetAttributeAsNumber added in v0.4.4

func (e *Entity) SetAttributeAsNumber(name string, value float64) error

func (*Entity) SetAttributeAsString

func (e *Entity) SetAttributeAsString(name string, value string) error

func (*Entity) SetAttributeAsText added in v0.4.3

func (e *Entity) SetAttributeAsText(name string, value string) error

func (*Entity) SetDateExpires added in v0.2.4

func (e *Entity) SetDateExpires(value time.Time)

func (*Entity) UnmarshalJSON

func (e *Entity) UnmarshalJSON(b []byte) error

type EntityMatcher added in v0.4.2

type EntityMatcher struct {
	Id          string `json:"id,omitempty"`
	IdPattern   string `json:"idPattern,omitempty"`
	Type        string `json:"type,omitempty"`
	TypePattern string `json:"typePattern,omitempty"`
}

func NewEntityMatcher added in v0.4.2

func NewEntityMatcher() *EntityMatcher

func (*EntityMatcher) ById added in v0.4.2

func (entityMatcher *EntityMatcher) ById(id string) *EntityMatcher

func (*EntityMatcher) ByIdPattern added in v0.4.2

func (entityMatcher *EntityMatcher) ByIdPattern(idPattern string) *EntityMatcher

func (*EntityMatcher) ByType added in v0.4.2

func (entityMatcher *EntityMatcher) ByType(typeName string) *EntityMatcher

func (*EntityMatcher) ByTypePattern added in v0.4.2

func (entityMatcher *EntityMatcher) ByTypePattern(typePattern string) *EntityMatcher

type GeoPoint

type GeoPoint struct {
	Latitude  float64
	Longitude float64
}

func NewGeoPoint

func NewGeoPoint(latitude float64, longitude float64) *GeoPoint

func (*GeoPoint) MarshalJSON

func (p *GeoPoint) MarshalJSON() ([]byte, error)

func (*GeoPoint) UnmarshalJSON

func (p *GeoPoint) UnmarshalJSON(b []byte) error

type GeorelModifier

type GeorelModifier string

func GeorelModifierMaxDistance

func GeorelModifierMaxDistance(maxDistance float64) GeorelModifier

func GeorelModifierMinDistance

func GeorelModifierMinDistance(minDistance float64) GeorelModifier

type GeospatialRelationship

type GeospatialRelationship string
const (
	GeorelNear       GeospatialRelationship = "near"
	GeorelCoveredBy  GeospatialRelationship = "coveredBy"
	GeorelIntersects GeospatialRelationship = "intersects"
	GeorelEquals     GeospatialRelationship = "equals"
	GeorelDisjoint   GeospatialRelationship = "disjoint"
)

type Metadata

type Metadata struct {
	// contains filtered or unexported fields
}

Metadata is a Context metadata, i.e. an optional part of the attribute.

type Notification added in v0.2.0

type Notification struct {
	Data           []*Entity `json:"data"`
	SubscriptionId string    `json:"subscriptionId"`
}

type OrionTime

type OrionTime struct {
	time.Time
}

func (OrionTime) MarshalJSON

func (t OrionTime) MarshalJSON() ([]byte, error)

type QueryExpression added in v0.4.2

type QueryExpression struct {
	Q        string                       `json:"q,omitempty"`
	Mq       string                       `json:"mq,omitempty"`
	Georel   GeospatialRelationship       `json:"georel,omitempty"`
	Geometry SimpleLocationFormatGeometry `json:"geometry,omitempty"`
	Coords   string                       `json:"coords,omitempty"`
}

type SimpleLocationFormatGeometry

type SimpleLocationFormatGeometry string
const (
	SLFPoint   SimpleLocationFormatGeometry = "point"
	SLFLine    SimpleLocationFormatGeometry = "line"
	SLFPolygon SimpleLocationFormatGeometry = "polygon"
	SLFBox     SimpleLocationFormatGeometry = "box"
)

type SimpleQueryOperator

type SimpleQueryOperator string
const (
	SQEqual              SimpleQueryOperator = "=="
	SQUnequal            SimpleQueryOperator = "!="
	SQGreaterThan        SimpleQueryOperator = ">"
	SQLessThan           SimpleQueryOperator = "<"
	SQGreaterOrEqualThan SimpleQueryOperator = ">="
	SQLessOrEqualThan    SimpleQueryOperator = "<="
	SQMatchPattern       SimpleQueryOperator = "~="
)

type SimpleQueryStatement

type SimpleQueryStatement string

func NewBinarySimpleQueryStatement

func NewBinarySimpleQueryStatement(attr string, operator SimpleQueryOperator, value string) (SimpleQueryStatement, error)

func NewBinarySimpleQueryStatementMultipleValues

func NewBinarySimpleQueryStatementMultipleValues(attr string, operator SimpleQueryOperator, values ...string) (SimpleQueryStatement, error)

func NewBinarySimpleQueryStatementRange

func NewBinarySimpleQueryStatementRange(attr string, operator SimpleQueryOperator, minimum string, maximum string) (SimpleQueryStatement, error)

type SimplifiedEntityRepresentation

type SimplifiedEntityRepresentation string

SimplifiedEntityRepresentation are representation modes to generate simplified representations of entitites. See: https://orioncontextbroker.docs.apiary.io/#introduction/specification/simplified-entity-representation

const (
	KeyValuesRepresentation SimplifiedEntityRepresentation = "keyValues"
	ValuesRepresentation    SimplifiedEntityRepresentation = "values"
	UniqueRepresentation    SimplifiedEntityRepresentation = "unique"
	CountRepresentation     SimplifiedEntityRepresentation = "count"
)

type Subscription

type Subscription struct {
	Id           string                    `json:"id,omitempty"`
	Description  string                    `json:"description,omitempty"`
	Subject      *SubscriptionSubject      `json:"subject,omitempty"`
	Notification *SubscriptionNotification `json:"notification,omitempty"`
	Expires      *OrionTime                `json:"expires,omitempty"`
	Status       SubscriptionStatus        `json:"status,omitempty"`
	Throttling   uint                      `json:"throttling,omitempty"`
}

type SubscriptionNotification

type SubscriptionNotification struct {
	Attrs            []string                            `json:"attrs,omitempty"`
	ExceptAttrs      []string                            `json:"exceptAttrs,omitempty"`
	Http             *SubscriptionNotificationHttp       `json:"http,omitempty"`
	HttpCustom       *SubscriptionNotificationHttpCustom `json:"httpCustom,omitempty"`
	AttrsFormat      string                              `json:"attrsFormat,omitempty"`
	Metadata         []string                            `json:"metadata,omitempty"`
	TimesSent        uint                                `json:"timesSent,omitempty"`
	LastNotification *time.Time                          `json:"lastNotification,omitempty"`
	LastFailure      *time.Time                          `json:"lastFailure,omitempty"`
	LastSuccess      *time.Time                          `json:"lastSuccess,omitempty"`
}

type SubscriptionNotificationHttp

type SubscriptionNotificationHttp struct {
	Url string `json:"url"`
}

type SubscriptionNotificationHttpCustom

type SubscriptionNotificationHttpCustom struct {
	Url     string            `json:"url"`
	Headers map[string]string `json:"headers,omitempty"`
	Qs      map[string]string `json:"qs,omitempty"`
	Method  string            `json:"method,omitempty"`
	Payload string            `json:"payload,omitempty"`
}

type SubscriptionStatus

type SubscriptionStatus string
const (
	SubscriptionActive   SubscriptionStatus = "active"
	SubscriptionInactive SubscriptionStatus = "inactive"
	SubscriptionExpired  SubscriptionStatus = "expired"
	SubscriptionFailed   SubscriptionStatus = "failed"
)

type SubscriptionSubject

type SubscriptionSubject struct {
	Entities  []*SubscriptionSubjectEntity  `json:"entities,omitempty"`
	Condition *SubscriptionSubjectCondition `json:"condition,omitempty"`
}

type SubscriptionSubjectCondition

type SubscriptionSubjectCondition struct {
	Attrs      []string                                `json:"attrs,omitempty"`
	Expression *SubscriptionSubjectConditionExpression `json:"expression,omitempty"`
}

type SubscriptionSubjectConditionExpression

type SubscriptionSubjectConditionExpression = QueryExpression

type SubscriptionSubjectEntity

type SubscriptionSubjectEntity = EntityMatcher

Jump to

Keyboard shortcuts

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