-
-
Notifications
You must be signed in to change notification settings - Fork 840
/
main.go
61 lines (54 loc) · 1.32 KB
/
main.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 (
"context"
"log"
"github.com/appleboy/gorush/rpc/proto"
structpb "github.com/golang/protobuf/ptypes/struct"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
const (
address = "localhost:9000"
)
func main() {
// Set up a connection to the server.
conn, err := grpc.NewClient(address, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Fatalf("did not connect: %v", err)
}
defer conn.Close()
c := proto.NewGorushClient(conn)
r, err := c.Send(context.Background(), &proto.NotificationRequest{
Platform: 2,
Tokens: []string{"1234567890"},
Message: "test message",
Badge: 1,
Category: "test",
Sound: "test",
Priority: proto.NotificationRequest_HIGH,
Alert: &proto.Alert{
Title: "Test Title",
Body: "Test Alert Body",
Subtitle: "Test Alert Sub Title",
LocKey: "Test loc key",
LocArgs: []string{"test", "test"},
},
Data: &structpb.Struct{
Fields: map[string]*structpb.Value{
"key1": {
Kind: &structpb.Value_StringValue{StringValue: "welcome"},
},
"key2": {
Kind: &structpb.Value_NumberValue{NumberValue: 2},
},
},
},
})
if err != nil {
log.Println("could not greet: ", err)
}
if r != nil {
log.Printf("Success: %t\n", r.Success)
log.Printf("Count: %d\n", r.Counts)
}
}