54 lines
1.2 KiB
Go
54 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
|
|
"git.wntrmute.dev/kyle/goutils/die"
|
|
pb "git.wntrmute.dev/kyle/overpush/proto"
|
|
"google.golang.org/grpc"
|
|
"google.golang.org/grpc/credentials/insecure"
|
|
)
|
|
|
|
func main() {
|
|
address := "127.0.0.1:5000"
|
|
m := &pb.Message{
|
|
Type: pb.MessageType_MessageTypeMessage,
|
|
Timestamp: time.Now().Unix(),
|
|
Priority: pb.Priority_PriorityNormal,
|
|
}
|
|
var r string
|
|
|
|
flag.StringVar(&address, "a", address, "`address` of overpush server")
|
|
flag.StringVar(&m.Text, "m", "this is a test message", "`message` text")
|
|
flag.StringVar(&m.Title, "t", "test test", "message title")
|
|
flag.StringVar(&r, "r", "", "recipients")
|
|
flag.Parse()
|
|
|
|
m.Recipients = strings.Split(r, ",")
|
|
|
|
if m.Text == "" && m.Title == "" {
|
|
die.With("no message or title specified")
|
|
}
|
|
|
|
if m.Title != "" {
|
|
m.Type = pb.MessageType_MessageTypeMessageWithTitle
|
|
}
|
|
|
|
var opts = []grpc.DialOption{
|
|
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
|
}
|
|
conn, err := grpc.Dial(address, opts...)
|
|
die.If(err)
|
|
defer conn.Close()
|
|
|
|
client := pb.NewOverpushClient(conn)
|
|
resp, err := client.QueueMessage(context.Background(), m)
|
|
die.If(err)
|
|
|
|
fmt.Printf("response status: %d\n", resp.Status)
|
|
}
|