From b25a30f355837be1e605587dc2fbf09ab9719a4a Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Fri, 9 Jun 2023 03:39:40 +0000 Subject: [PATCH] bad commit ignored cmd --- .gitignore | 4 ++-- cmd/overpush/main.go | 53 +++++++++++++++++++++++++++++++++++++++++++ cmd/overpushd/main.go | 41 +++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 cmd/overpush/main.go create mode 100644 cmd/overpushd/main.go diff --git a/.gitignore b/.gitignore index a982e29..d09c945 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ *.conf -overpush -overpushd +/overpush +/overpushd diff --git a/cmd/overpush/main.go b/cmd/overpush/main.go new file mode 100644 index 0000000..491f12c --- /dev/null +++ b/cmd/overpush/main.go @@ -0,0 +1,53 @@ +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) +} diff --git a/cmd/overpushd/main.go b/cmd/overpushd/main.go new file mode 100644 index 0000000..3bbb6a1 --- /dev/null +++ b/cmd/overpushd/main.go @@ -0,0 +1,41 @@ +package main + +import ( + "flag" + "fmt" + + "git.wntrmute.dev/kyle/goutils/config" + "git.wntrmute.dev/kyle/goutils/die" + "git.wntrmute.dev/kyle/goutils/log" + "git.wntrmute.dev/kyle/overpush/server" +) + +func main() { + var configFile string + + flag.StringVar(&configFile, "f", "", "`path` to config file") + flag.Parse() + + if configFile != "" { + err := config.LoadFile(configFile) + die.If(err) + } + + logLevel := config.GetDefault("log_level", "WARNING") + opts := log.DefaultOptions("overpush", false) + opts.Level = logLevel + + fmt.Println("listing keys:") + for _, k := range config.ListKeys() { + fmt.Printf("\t%s\n", k) + } + + err := log.Setup(opts) + die.If(err) + + srv, err := server.New() + log.FatalError(err, "failed to set up gRPC server") + go srv.Default.Receive() + + log.FatalError(server.Run(srv), "server has died") +}