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, issuemail string) SpaceInfo {
41 nsi["contact"] = SpaceInfo{
46 "issue-mail": issuemail}
47 nsi["issue-report-channels"] = [3]string{"issue-mail","email","ml"}
51 func (nsi SpaceInfo) AddSpaceFeed(name, mimetype, url string) SpaceInfo {
52 newfeed := SpaceInfo{"name": name, "type": mimetype, "url": url}
53 if nsi["feeds"] == nil {
54 feedlist := make([]SpaceInfo, 1)
56 nsi["feeds"] = feedlist
58 feedlist, ok := nsi["feeds"].([]SpaceInfo) //type assertion (panics if false)
60 nsi["feeds"] = append(feedlist, newfeed)
62 panic("Wrong Type of feedlist: Should never happen")
68 func (nsi SpaceInfo) AddSpaceEvent(name, eventtype, extra string) SpaceInfo {
69 newevent := SpaceInfo{"name": name, "type": eventtype, "timestamp": time.Now().Unix(), "extra": extra}
70 if nsi["events"] == nil {
71 eventlist := make([]SpaceInfo, 1)
72 eventlist[0] = newevent
73 nsi["events"] = eventlist
75 eventlist, ok := nsi["events"].([]SpaceInfo) //type assertion
77 if len(eventlist) >= max_num_events {
78 eventlist = eventlist[1:]
80 nsi["events"] = append(eventlist, newevent)
82 panic("Wrong Type of eventlist: Should never happen")
88 func (nsi SpaceInfo) AddSpaceAddress(address string) SpaceInfo {
89 nsi["address"] = address
90 if nsi["location"] != nil {
91 location, ok := nsi["location"].(SpaceInfo)
93 location["address"] = address
99 func (nsi SpaceInfo) SetStatus(open bool, status string) {
100 nsi["status"] = status
102 nsi["lastchange"] = time.Now().Unix()
103 state, ok := nsi["state"].(SpaceInfo)
105 state["message"] = status
107 state["lastchange"] = nsi["lastchange"]
111 func NewSpaceInfo(space string, url string, logo string, open_icon string, closed_icon string, lat float64, lon float64) SpaceInfo {
112 nsi := map[string]interface{}{
118 "lastchange": time.Now().Unix(),
121 "closed": closed_icon,
125 "lastchange":time.Now().Unix(),
128 "closed": closed_icon},
130 "location": SpaceInfo{
133 "contact" : SpaceInfo {},
138 func (data SpaceInfo) MakeJSON() ([]byte, error) {
139 msg, err := json.Marshal(data)