2017-07-24 07:06:23 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-11-14 06:18:48 +00:00
|
|
|
"context"
|
2017-07-24 07:06:23 +00:00
|
|
|
"log"
|
|
|
|
|
2017-11-12 14:44:33 +00:00
|
|
|
"github.com/appleboy/gorush/rpc/proto"
|
|
|
|
|
2019-05-21 06:33:35 +00:00
|
|
|
structpb "github.com/golang/protobuf/ptypes/struct"
|
2017-07-24 07:06:23 +00:00
|
|
|
"google.golang.org/grpc"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2017-10-19 01:24:47 +00:00
|
|
|
address = "localhost:9000"
|
2017-07-24 07:06:23 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
// Set up a connection to the server.
|
|
|
|
conn, err := grpc.Dial(address, grpc.WithInsecure())
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("did not connect: %v", err)
|
|
|
|
}
|
|
|
|
defer conn.Close()
|
2017-11-12 14:44:33 +00:00
|
|
|
c := proto.NewGorushClient(conn)
|
2017-07-24 07:06:23 +00:00
|
|
|
|
2017-11-12 14:44:33 +00:00
|
|
|
r, err := c.Send(context.Background(), &proto.NotificationRequest{
|
2017-07-24 07:06:23 +00:00
|
|
|
Platform: 2,
|
|
|
|
Tokens: []string{"1234567890"},
|
|
|
|
Message: "test message",
|
2018-01-02 07:53:15 +00:00
|
|
|
Badge: 1,
|
|
|
|
Category: "test",
|
2018-01-04 03:31:03 +00:00
|
|
|
Sound: "test",
|
2021-10-25 01:34:46 +00:00
|
|
|
Priority: proto.NotificationRequest_HIGH,
|
2018-01-03 09:08:28 +00:00
|
|
|
Alert: &proto.Alert{
|
2018-01-02 07:53:15 +00:00
|
|
|
Title: "Test Title",
|
|
|
|
Body: "Test Alert Body",
|
|
|
|
Subtitle: "Test Alert Sub Title",
|
2018-01-06 07:03:21 +00:00
|
|
|
LocKey: "Test loc key",
|
|
|
|
LocArgs: []string{"test", "test"},
|
2018-01-02 07:53:15 +00:00
|
|
|
},
|
2019-05-21 06:10:32 +00:00
|
|
|
Data: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
"key1": {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: "welcome"},
|
|
|
|
},
|
|
|
|
"key2": {
|
|
|
|
Kind: &structpb.Value_NumberValue{NumberValue: 2},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-07-24 07:06:23 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
2021-08-04 01:00:04 +00:00
|
|
|
log.Println("could not greet: ", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if r != nil {
|
|
|
|
log.Printf("Success: %t\n", r.Success)
|
|
|
|
log.Printf("Count: %d\n", r.Counts)
|
2017-07-24 07:06:23 +00:00
|
|
|
}
|
|
|
|
}
|