-
Notifications
You must be signed in to change notification settings - Fork 0
/
cass.go
45 lines (36 loc) · 975 Bytes
/
cass.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"log"
"github.com/hailocab/gocassa"
)
var keySpace gocassa.KeySpace
var plantMap map[string]gocassa.MultimapTable
func Initialize() {
log.Println("Initializing GoCassa")
var err error
connection, _ := gocassa.Connect([]string{"api.skydome.io"}, "", "")
connection.CreateKeySpace("test")
keySpace, err = gocassa.ConnectToKeySpace("test", []string{"api.skydome.io"}, "", "")
if err != nil {
panic(err)
}
plantMap = map[string]gocassa.MultimapTable{}
}
func WriteToCassandra(plantId string, pheremone Pheremone) {
log.Println("Writing pheremone: ", pheremone)
log.Println("With plantId: ", plantId)
plant := plantMap[plantId]
if plant == nil {
plant = keySpace.MultimapTable(plantId, "Ant", "At", Pheremone{})
log.Print("creating table : ", plantId)
err := plant.Create()
if err != nil {
log.Println("Error:", err)
}
plantMap[plantId] = plant
}
err := plant.Set(pheremone).Run()
if err != nil {
panic(err)
}
}