/
example.go
52 lines (43 loc) · 905 Bytes
/
example.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
46
47
48
49
50
51
52
package main
import (
"fmt"
"os"
"github.com/bmorton/go-azure/azure"
"github.com/bmorton/go-azure/table"
"github.com/k0kubun/pp"
)
type Message struct {
Body string
RowKey string
PartitionKey string
}
func main() {
c := table.New(azure.StorageCredentials{
AccountName: os.Getenv("AZURE_STORAGE_ACCOUNT_NAME"),
AccessKey: os.Getenv("AZURE_STORAGE_ACCESS_KEY"),
})
c.Debug = true
err := c.Create("messages")
if err != nil {
fmt.Println(err)
}
err = c.Insert("messages", Message{
Body: "My message body!",
RowKey: "1",
PartitionKey: "network-1",
})
if err != nil {
fmt.Println(err)
}
m := &Message{}
err = c.GetEntity(table.RowQuery{
Table: "messages",
PartitionKey: "network-1",
RowKey: "1",
Fields: []string{"Body", "RowKey", "PartitionKey"},
}, m)
if err != nil {
fmt.Println(err)
}
pp.Println(m)
}