Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var MarkerValue = &Value{ kind: HaystackTypeMarker, }
MarkerValue ...
Functions ¶
This section is empty.
Types ¶
type Entity ¶ added in v0.1.0
type Entity struct { Dis string // Dis is public because it is mutable // contains filtered or unexported fields }
An Entity is an abstraction for some physical object in the real world. Entity carries its tags and an ID
type Grid ¶
Grid is a simple database structure, column based
Example ¶
g := NewGrid() myTagLabel := NewLabel("mytag") myTagSite := NewLabel("site") myTagLabel.Display = "the display" mySite := NewHaystackID("myreference") entity := g.NewEntity(mySite) myTagValue := NewStr("foo") entity.SetTag(myTagLabel, myTagValue) entity.SetTag(myTagSite, MarkerValue) // Do something with the grid ... :D // ... // Encode it in json enc := json.NewEncoder(os.Stdout) err := enc.Encode(g) if err != nil { log.Fatal(err) }
Output:
func (*Grid) GetEntities ¶ added in v0.1.0
GetEntities from the grid
func (*Grid) GetEntityByID ¶ added in v0.1.4
func (g *Grid) GetEntityByID(id *HaystackID) *Entity
GetEntityByID returns the entity identified by id, or nil if nothing is found if a grid has two elements with the same ID (there is no fence to protect from that), only the first one is returned
func (*Grid) MarshalJSON ¶
MarshalJSON in haystack compatible format
func (*Grid) NewEntity ¶ added in v0.1.0
func (g *Grid) NewEntity(id *HaystackID) *Entity
NewEntity identified by id. it returns an error if the ID is already taken. It is the responsibility of the caller to ensure that the ID does not exists yet in the grid.
func (*Grid) UnmarshalJSON ¶
UnmarshalJSON turns a JSON encoded grid into a Grid object
type HaystackID ¶ added in v0.1.0
type HaystackID string
HaystackID is a Unique identifier for an entity. see https://www.project-haystack.org/doc/TagModel#Id
func NewHaystackID ¶ added in v0.1.0
func NewHaystackID(s string) *HaystackID
NewHaystackID from string s
type Kind ¶ added in v0.0.6
type Kind int
Kind is a supported type for a haystack value
const ( // HaystackTypeUndefined ... HaystackTypeUndefined Kind = iota // HaystackTypeGrid is a Grid object HaystackTypeGrid // HaystackTypeList Array HaystackTypeList // HaystackTypeDict Object HaystackTypeDict // HaystackTypeNull null HaystackTypeNull // HaystackTypeBool Boolean HaystackTypeBool // HaystackTypeMarker "m:" HaystackTypeMarker // HaystackTypeRemove "-:" HaystackTypeRemove // HaystackTypeNA "z:" HaystackTypeNA // HaystackTypeNumber "n:<float> [unit]" "n:45.5" "n:73.2 °F" "n:-INF" HaystackTypeNumber // HaystackTypeRef "r:<id> [dis]" "r:abc-123" "r:abc-123 RTU #3" HaystackTypeRef // HaystackTypeStr "hello" "s:hello" HaystackTypeStr // HaystackTypeDate "d:2014-01-03" HaystackTypeDate // HaystackTypeTime "h:23:59:00" HaystackTypeTime // HaystackTypeDateTime "t:2015-06-08T15:47:41-04:00 New_York" HaystackTypeDateTime // HaystackTypeURI "u:http://project-haystack.org/" HaystackTypeURI // HaystackTypeCoord "c:<lat>,<lng>" "c:37.545,-77.449" HaystackTypeCoord //HaystackTypeXStr "x:Type:value" HaystackTypeXStr // HaystackLastType ... HaystackLastType )
type Label ¶ added in v0.1.0
Label of a tag. Label is a string and for efficiency we are using pointer to Label in the entities
type Value ¶ added in v0.1.0
type Value struct {
// contains filtered or unexported fields
}
Value is an haystack value
func (*Value) GetHaystackID ¶ added in v0.1.2
func (v *Value) GetHaystackID() (*HaystackID, error)
GetHaystackID Returns the underlying value of the reference
func (*Value) GetString ¶ added in v0.1.0
GetString value; returns an error if the underlying type is not an haystack string
func (*Value) MarshalJSON ¶ added in v0.1.0
MarshalJSON encode the value in format compatible with haystack's JSON: https://www.project-haystack.org/doc/Json
func (*Value) UnmarshalJSON ¶ added in v0.1.0
UnmarshalJSON extract a value from b