9 const max_num_events int = 4
11 type SpaceInfo map[string]interface{}
13 func (nsi SpaceInfo) UpdateSensorData(what, where, value string) {
14 if nsi["sensors"] == nil {
15 sensorlist := make([]SpaceInfo, 1)
16 sensorlist[0] = SpaceInfo{what: SpaceInfo{where: value}}
17 nsi["sensors"] = sensorlist
19 sensorlist, ok := nsi["sensors"].([]SpaceInfo) //type assertion (panics if false)
21 for _, sensor := range sensorlist {
22 if sensor[what] != nil {
23 sensorinfo, ok2 := sensor[what].(SpaceInfo)
25 sensorinfo[where] = value
28 panic("Wrong Type of sensorinfo: Should never happen")
33 nsi["sensors"] = append(sensorlist, SpaceInfo{what: SpaceInfo{where: value}})
35 panic("Wrong Type of sensorlist: Should never happen")
40 func (nsi SpaceInfo) AddSpaceContactInfo(phone, irc, email, ml, jabber string) SpaceInfo {
41 nsi["contact"] = SpaceInfo{
49 func (nsi SpaceInfo) AddSpaceFeed(name, mimetype, url string) SpaceInfo {
50 newfeed := SpaceInfo{"name": name, "type": mimetype, "url": url}
51 if nsi["feeds"] == nil {
52 feedlist := make([]SpaceInfo, 1)
54 nsi["feeds"] = feedlist
56 feedlist, ok := nsi["feeds"].([]SpaceInfo) //type assertion (panics if false)
58 nsi["feeds"] = append(feedlist, newfeed)
60 panic("Wrong Type of feedlist: Should never happen")
66 func (nsi SpaceInfo) AddSpaceEvent(name, eventtype, extra string) SpaceInfo {
67 newevent := SpaceInfo{"name": name, "type": eventtype, "t": time.Now().Unix(), "extra": extra}
68 if nsi["events"] == nil {
69 eventlist := make([]SpaceInfo, 1)
70 eventlist[0] = newevent
71 nsi["events"] = eventlist
73 eventlist, ok := nsi["events"].([]SpaceInfo) //type assertion
75 if len(eventlist) >= max_num_events {
76 eventlist = eventlist[1:]
78 nsi["events"] = append(eventlist, newevent)
80 panic("Wrong Type of eventlist: Should never happen")
86 func (nsi SpaceInfo) AddSpaceAddress(address string) SpaceInfo {
87 nsi["address"] = address
91 func (nsi SpaceInfo) AddSpaceLatLon(lat float64, lon float64) SpaceInfo {
97 func (nsi SpaceInfo) SetStatus(open bool, status string) {
98 nsi["status"] = status
100 nsi["lastchange"] = time.Now().Unix()
103 func NewSpaceInfo(space string, url string, logo string, open_icon string, closed_icon string) SpaceInfo {
104 nsi := map[string]interface{}{
110 "lastchange": time.Now().Unix(),
111 "icon": map[string]interface{}{
113 "closed": closed_icon}}
117 func (data SpaceInfo) MakeJSON() ([]byte, error) {
118 msg, err := json.Marshal(data)