-
Notifications
You must be signed in to change notification settings - Fork 2
/
example.go
61 lines (48 loc) · 1.44 KB
/
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
53
54
55
56
57
58
59
60
61
package main
import (
"fmt"
"log"
infoNode "github.com/allancapistrano/tangle-client-go/info"
"github.com/allancapistrano/tangle-client-go/messages"
)
func main() {
nodeURL := "http://127.0.0.1:14265"
// Network info
nodeInfo, err := infoNode.GetNodeInfo(nodeURL)
if err != nil {
log.Fatal(err)
}
fmt.Println(nodeInfo)
// All Network info
allNodeInfo, err := infoNode.GetAllNodeInfo(nodeURL)
if err != nil {
log.Fatal(err)
}
fmt.Println(allNodeInfo)
// Submitting some message.
messages.SubmitMessage(nodeURL, "LB_STATUS", "{\"available\":true,\"avgLoad\":3,\"createdAt\":1695652263921,\"group\":\"group3\",\"lastLoad\":4,\"publishedAt\":1695652267529,\"source\":\"source4\",\"type\":\"LB_STATUS\"}", 15)
// Reading some messages by an index.
messagesByIndex, err := messages.GetAllMessagesByIndex(nodeURL, "LB_STATUS")
if err != nil {
log.Fatal(err)
}
for _, v := range messagesByIndex {
fmt.Printf("Index: %s | Data: %s\n", v.Index, v.Data)
}
messageID := "d57c9ad40b7079fd8e36cd3d127b3aed9fff7e3f293f1fe1913b4d850ba0814d"
message, err := messages.GetMessageFormattedByMessageID(
nodeURL,
messageID,
)
if err != nil {
log.Fatal(err)
}
fmt.Println(message.Index)
fmt.Println(message.Data)
// Reading max of three messages by an index.
limitedMessages, err := messages.GetLastHourMessagesByIndex(nodeURL, "92015a2d-4bae-428d-a428-6338f465e72c", 1)
if err != nil {
log.Fatal(err)
}
fmt.Println(limitedMessages)
}