From 9e97f9842bd129cc3c731734c4b455751513e486 Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Thu, 25 May 2023 06:57:56 +0000 Subject: [PATCH] C O M P U T E R --- .gitignore | 0 core/core.go | 58 +++++++ go.mod | 11 ++ go.sum | 21 +++ proto/Makefile | 6 +- proto/alert.proto | 17 -- proto/message.pb.go | 344 +++++++++++++++++++++++++++++++++++++++ proto/message.proto | 33 ++++ proto/response.pb.go | 229 ++++++++++++++++++++++++++ proto/response.proto | 19 +++ proto/service.pb.go | 74 +++++++++ proto/service.proto | 11 ++ proto/service_grpc.pb.go | 109 +++++++++++++ 13 files changed, 913 insertions(+), 19 deletions(-) create mode 100644 .gitignore create mode 100644 core/core.go create mode 100644 go.sum delete mode 100644 proto/alert.proto create mode 100644 proto/message.pb.go create mode 100644 proto/message.proto create mode 100644 proto/response.pb.go create mode 100644 proto/response.proto create mode 100644 proto/service.pb.go create mode 100644 proto/service.proto create mode 100644 proto/service_grpc.pb.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/core/core.go b/core/core.go new file mode 100644 index 0000000..e408cd8 --- /dev/null +++ b/core/core.go @@ -0,0 +1,58 @@ +package core + +import ( + "fmt" + "sync" + "time" + + pb "git.wntrmute.dev/kyle/overpush/proto" + "github.com/gregdel/pushover" +) + +// MessageBuffer is how many messages to back up. This represents a +// balance between expected usage and anticipated spikes. It is +// entirely empirical as I don't have data to drive this decision. +const MessageBuffer = 16 + +type Account struct { + p *pushover.Pushover + nextTransmit time.Time + q chan pb.Message + lock *sync.Mutex +} + +func NewAccount(token string) *Account { + return &Account{ + p: pushover.New(token), + q: make(chan pb.Message, MessageBuffer), + lock: &sync.Mutex{}, + } +} + +func (a *Account) UpdateLimit(limit *pushover.Limit) { + a.lock.Lock() + if limit.Remaining > 0 { + return + } + + a.nextTransmit = limit.NextReset.Add(time.Second) +} + +func (a *Account) Receive() { + for { + for { + if a.nextTransmit.After(time.Now()) { + sleep := time.Until(a.nextTransmit) + time.Sleep(sleep) + } else { + break + } + } + m, closed := <-a.q + if closed { + panic("channel closed") + } + + fmt.Println(m.String()) + } +} diff --git a/go.mod b/go.mod index 63542b4..4aa4a21 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,14 @@ module git.wntrmute.dev/kyle/overpush go 1.20 + +require ( + github.com/golang/protobuf v1.5.3 // indirect + github.com/gregdel/pushover v1.2.0 // indirect + golang.org/x/net v0.8.0 // indirect + golang.org/x/sys v0.6.0 // indirect + golang.org/x/text v0.8.0 // indirect + google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 // indirect + google.golang.org/grpc v1.55.0 // indirect + google.golang.org/protobuf v1.30.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..310941a --- /dev/null +++ b/go.sum @@ -0,0 +1,21 @@ +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= +github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/gregdel/pushover v1.2.0 h1:SLnpvJijUyEZvkJNyrldGhFhryYgQYlThSLpB5Oqt5k= +github.com/gregdel/pushover v1.2.0/go.mod h1:EcaO66Nn1StkpEm1iKtBTV3d2A16SoMsVER1PthX7to= +golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ= +golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= +golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68= +golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 h1:DdoeryqhaXp1LtT/emMP1BRJPHHKFi5akj/nbx/zNTA= +google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4/go.mod h1:NWraEVixdDnqcqQ30jipen1STv2r/n24Wb7twVTGR4s= +google.golang.org/grpc v1.55.0 h1:3Oj82/tFSCeUrRTg/5E/7d/W5A1tj6Ky1ABAuZuv5ag= +google.golang.org/grpc v1.55.0/go.mod h1:iYEXKGkEBhg1PjZQvoYEVPTDkHo1/bjTnfwTeGONTY8= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= +google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= diff --git a/proto/Makefile b/proto/Makefile index fbfc57e..3d14b6a 100644 --- a/proto/Makefile +++ b/proto/Makefile @@ -1,12 +1,14 @@ PROTOFILES = $(wildcard *.proto) GO_TARGETS = $(patsubst %.proto,%.pb.go,$(PROTOFILES)) -DEBIAN_DEPS = protobuf-compiler protoc-gen-go +DEBIAN_DEPS = protobuf-compiler protoc-gen-go protobuf-compiler-grpc \ + golang-goprotobuf-dev golang-google-genproto-dev \ + golang-google-grpc-dev grpc-proto golang-protobuf-extensions-dev .PHONY: all all: $(GO_TARGETS) %.pb.go: %.proto - protoc -I=$(PWD) --go_out=$(PWD) $< + protoc -I=$(PWD) --go_out=$(PWD) --go-grpc_out=. --go-grpc_opt=paths=source_relative $< .PHONY: install-debian-deps install-debian-deps: diff --git a/proto/alert.proto b/proto/alert.proto deleted file mode 100644 index 34907a8..0000000 --- a/proto/alert.proto +++ /dev/null @@ -1,17 +0,0 @@ -syntax = 'proto3'; -package overpush; - -option go_package = '.;pb'; - -enum AlertType { - AlertTypeInvalid = 0; - AlertTypeMessage = 1; - AlertTypeMessageWithTitle = 2; - AlertTypeMessageWithAttachment = 3; -} - -message Alert { - string title = 3; - string text = 4; - bytes attachment = 5; -} diff --git a/proto/message.pb.go b/proto/message.pb.go new file mode 100644 index 0000000..e88cddd --- /dev/null +++ b/proto/message.pb.go @@ -0,0 +1,344 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.30.0 +// protoc v3.12.4 +// source: message.proto + +package pb + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type AlertType int32 + +const ( + AlertType_AlertTypeInvalid AlertType = 0 + AlertType_AlertTypeMessage AlertType = 1 + AlertType_AlertTypeMessageWithTitle AlertType = 2 + AlertType_AlertTypeMessageWithAttachment AlertType = 3 +) + +// Enum value maps for AlertType. +var ( + AlertType_name = map[int32]string{ + 0: "AlertTypeInvalid", + 1: "AlertTypeMessage", + 2: "AlertTypeMessageWithTitle", + 3: "AlertTypeMessageWithAttachment", + } + AlertType_value = map[string]int32{ + "AlertTypeInvalid": 0, + "AlertTypeMessage": 1, + "AlertTypeMessageWithTitle": 2, + "AlertTypeMessageWithAttachment": 3, + } +) + +func (x AlertType) Enum() *AlertType { + p := new(AlertType) + *p = x + return p +} + +func (x AlertType) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (AlertType) Descriptor() protoreflect.EnumDescriptor { + return file_message_proto_enumTypes[0].Descriptor() +} + +func (AlertType) Type() protoreflect.EnumType { + return &file_message_proto_enumTypes[0] +} + +func (x AlertType) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use AlertType.Descriptor instead. +func (AlertType) EnumDescriptor() ([]byte, []int) { + return file_message_proto_rawDescGZIP(), []int{0} +} + +type Priority int32 + +const ( + Priority_PriorityInvalid Priority = 0 + Priority_PriorityLowest Priority = 1 + Priority_PriorityLow Priority = 2 + Priority_PriorityNormal Priority = 3 + Priority_PriorityHigh Priority = 4 + Priority_PriorityEmergency Priority = 5 +) + +// Enum value maps for Priority. +var ( + Priority_name = map[int32]string{ + 0: "PriorityInvalid", + 1: "PriorityLowest", + 2: "PriorityLow", + 3: "PriorityNormal", + 4: "PriorityHigh", + 5: "PriorityEmergency", + } + Priority_value = map[string]int32{ + "PriorityInvalid": 0, + "PriorityLowest": 1, + "PriorityLow": 2, + "PriorityNormal": 3, + "PriorityHigh": 4, + "PriorityEmergency": 5, + } +) + +func (x Priority) Enum() *Priority { + p := new(Priority) + *p = x + return p +} + +func (x Priority) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (Priority) Descriptor() protoreflect.EnumDescriptor { + return file_message_proto_enumTypes[1].Descriptor() +} + +func (Priority) Type() protoreflect.EnumType { + return &file_message_proto_enumTypes[1] +} + +func (x Priority) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use Priority.Descriptor instead. +func (Priority) EnumDescriptor() ([]byte, []int) { + return file_message_proto_rawDescGZIP(), []int{1} +} + +type Message struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Timestamp uint64 `protobuf:"varint,1,opt,name=timestamp,proto3" json:"timestamp,omitempty"` + Type AlertType `protobuf:"varint,2,opt,name=type,proto3,enum=overpush.AlertType" json:"type,omitempty"` + Priority Priority `protobuf:"varint,3,opt,name=priority,proto3,enum=overpush.Priority" json:"priority,omitempty"` + Recipients []string `protobuf:"bytes,4,rep,name=recipients,proto3" json:"recipients,omitempty"` + StreamName string `protobuf:"bytes,5,opt,name=stream_name,json=streamName,proto3" json:"stream_name,omitempty"` // string transmitter = 6; + Title string `protobuf:"bytes,8,opt,name=title,proto3" json:"title,omitempty"` + Text string `protobuf:"bytes,9,opt,name=text,proto3" json:"text,omitempty"` + Attachment []byte `protobuf:"bytes,10,opt,name=attachment,proto3" json:"attachment,omitempty"` +} + +func (x *Message) Reset() { + *x = Message{} + if protoimpl.UnsafeEnabled { + mi := &file_message_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Message) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Message) ProtoMessage() {} + +func (x *Message) ProtoReflect() protoreflect.Message { + mi := &file_message_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Message.ProtoReflect.Descriptor instead. +func (*Message) Descriptor() ([]byte, []int) { + return file_message_proto_rawDescGZIP(), []int{0} +} + +func (x *Message) GetTimestamp() uint64 { + if x != nil { + return x.Timestamp + } + return 0 +} + +func (x *Message) GetType() AlertType { + if x != nil { + return x.Type + } + return AlertType_AlertTypeInvalid +} + +func (x *Message) GetPriority() Priority { + if x != nil { + return x.Priority + } + return Priority_PriorityInvalid +} + +func (x *Message) GetRecipients() []string { + if x != nil { + return x.Recipients + } + return nil +} + +func (x *Message) GetStreamName() string { + if x != nil { + return x.StreamName + } + return "" +} + +func (x *Message) GetTitle() string { + if x != nil { + return x.Title + } + return "" +} + +func (x *Message) GetText() string { + if x != nil { + return x.Text + } + return "" +} + +func (x *Message) GetAttachment() []byte { + if x != nil { + return x.Attachment + } + return nil +} + +var File_message_proto protoreflect.FileDescriptor + +var file_message_proto_rawDesc = []byte{ + 0x0a, 0x0d, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, + 0x08, 0x6f, 0x76, 0x65, 0x72, 0x70, 0x75, 0x73, 0x68, 0x22, 0x8b, 0x02, 0x0a, 0x07, 0x4d, 0x65, + 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, + 0x6d, 0x70, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, + 0x61, 0x6d, 0x70, 0x12, 0x27, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x0e, 0x32, 0x13, 0x2e, 0x6f, 0x76, 0x65, 0x72, 0x70, 0x75, 0x73, 0x68, 0x2e, 0x41, 0x6c, 0x65, + 0x72, 0x74, 0x54, 0x79, 0x70, 0x65, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x2e, 0x0a, 0x08, + 0x70, 0x72, 0x69, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x12, + 0x2e, 0x6f, 0x76, 0x65, 0x72, 0x70, 0x75, 0x73, 0x68, 0x2e, 0x50, 0x72, 0x69, 0x6f, 0x72, 0x69, + 0x74, 0x79, 0x52, 0x08, 0x70, 0x72, 0x69, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x12, 0x1e, 0x0a, 0x0a, + 0x72, 0x65, 0x63, 0x69, 0x70, 0x69, 0x65, 0x6e, 0x74, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x09, + 0x52, 0x0a, 0x72, 0x65, 0x63, 0x69, 0x70, 0x69, 0x65, 0x6e, 0x74, 0x73, 0x12, 0x1f, 0x0a, 0x0b, + 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0a, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, + 0x05, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x69, + 0x74, 0x6c, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x65, 0x78, 0x74, 0x18, 0x09, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x04, 0x74, 0x65, 0x78, 0x74, 0x12, 0x1e, 0x0a, 0x0a, 0x61, 0x74, 0x74, 0x61, 0x63, + 0x68, 0x6d, 0x65, 0x6e, 0x74, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0a, 0x61, 0x74, 0x74, + 0x61, 0x63, 0x68, 0x6d, 0x65, 0x6e, 0x74, 0x2a, 0x7a, 0x0a, 0x09, 0x41, 0x6c, 0x65, 0x72, 0x74, + 0x54, 0x79, 0x70, 0x65, 0x12, 0x14, 0x0a, 0x10, 0x41, 0x6c, 0x65, 0x72, 0x74, 0x54, 0x79, 0x70, + 0x65, 0x49, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x10, 0x00, 0x12, 0x14, 0x0a, 0x10, 0x41, 0x6c, + 0x65, 0x72, 0x74, 0x54, 0x79, 0x70, 0x65, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x10, 0x01, + 0x12, 0x1d, 0x0a, 0x19, 0x41, 0x6c, 0x65, 0x72, 0x74, 0x54, 0x79, 0x70, 0x65, 0x4d, 0x65, 0x73, + 0x73, 0x61, 0x67, 0x65, 0x57, 0x69, 0x74, 0x68, 0x54, 0x69, 0x74, 0x6c, 0x65, 0x10, 0x02, 0x12, + 0x22, 0x0a, 0x1e, 0x41, 0x6c, 0x65, 0x72, 0x74, 0x54, 0x79, 0x70, 0x65, 0x4d, 0x65, 0x73, 0x73, + 0x61, 0x67, 0x65, 0x57, 0x69, 0x74, 0x68, 0x41, 0x74, 0x74, 0x61, 0x63, 0x68, 0x6d, 0x65, 0x6e, + 0x74, 0x10, 0x03, 0x2a, 0x81, 0x01, 0x0a, 0x08, 0x50, 0x72, 0x69, 0x6f, 0x72, 0x69, 0x74, 0x79, + 0x12, 0x13, 0x0a, 0x0f, 0x50, 0x72, 0x69, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x49, 0x6e, 0x76, 0x61, + 0x6c, 0x69, 0x64, 0x10, 0x00, 0x12, 0x12, 0x0a, 0x0e, 0x50, 0x72, 0x69, 0x6f, 0x72, 0x69, 0x74, + 0x79, 0x4c, 0x6f, 0x77, 0x65, 0x73, 0x74, 0x10, 0x01, 0x12, 0x0f, 0x0a, 0x0b, 0x50, 0x72, 0x69, + 0x6f, 0x72, 0x69, 0x74, 0x79, 0x4c, 0x6f, 0x77, 0x10, 0x02, 0x12, 0x12, 0x0a, 0x0e, 0x50, 0x72, + 0x69, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x4e, 0x6f, 0x72, 0x6d, 0x61, 0x6c, 0x10, 0x03, 0x12, 0x10, + 0x0a, 0x0c, 0x50, 0x72, 0x69, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x48, 0x69, 0x67, 0x68, 0x10, 0x04, + 0x12, 0x15, 0x0a, 0x11, 0x50, 0x72, 0x69, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x45, 0x6d, 0x65, 0x72, + 0x67, 0x65, 0x6e, 0x63, 0x79, 0x10, 0x05, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_message_proto_rawDescOnce sync.Once + file_message_proto_rawDescData = file_message_proto_rawDesc +) + +func file_message_proto_rawDescGZIP() []byte { + file_message_proto_rawDescOnce.Do(func() { + file_message_proto_rawDescData = protoimpl.X.CompressGZIP(file_message_proto_rawDescData) + }) + return file_message_proto_rawDescData +} + +var file_message_proto_enumTypes = make([]protoimpl.EnumInfo, 2) +var file_message_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_message_proto_goTypes = []interface{}{ + (AlertType)(0), // 0: overpush.AlertType + (Priority)(0), // 1: overpush.Priority + (*Message)(nil), // 2: overpush.Message +} +var file_message_proto_depIdxs = []int32{ + 0, // 0: overpush.Message.type:type_name -> overpush.AlertType + 1, // 1: overpush.Message.priority:type_name -> overpush.Priority + 2, // [2:2] is the sub-list for method output_type + 2, // [2:2] is the sub-list for method input_type + 2, // [2:2] is the sub-list for extension type_name + 2, // [2:2] is the sub-list for extension extendee + 0, // [0:2] is the sub-list for field type_name +} + +func init() { file_message_proto_init() } +func file_message_proto_init() { + if File_message_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_message_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Message); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_message_proto_rawDesc, + NumEnums: 2, + NumMessages: 1, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_message_proto_goTypes, + DependencyIndexes: file_message_proto_depIdxs, + EnumInfos: file_message_proto_enumTypes, + MessageInfos: file_message_proto_msgTypes, + }.Build() + File_message_proto = out.File + file_message_proto_rawDesc = nil + file_message_proto_goTypes = nil + file_message_proto_depIdxs = nil +} diff --git a/proto/message.proto b/proto/message.proto new file mode 100644 index 0000000..5911716 --- /dev/null +++ b/proto/message.proto @@ -0,0 +1,33 @@ +syntax = 'proto3'; +package overpush; + +option go_package = '.;pb'; + +enum AlertType { + AlertTypeInvalid = 0; + AlertTypeMessage = 1; + AlertTypeMessageWithTitle = 2; + AlertTypeMessageWithAttachment = 3; +} + +enum Priority { + PriorityInvalid = 0; + PriorityLowest = 1; + PriorityLow = 2; + PriorityNormal = 3; + PriorityHigh = 4; + PriorityEmergency = 5; +} + +message Message { + uint64 timestamp = 1; + AlertType type = 2; + Priority priority = 3; + repeated string recipients = 4; + string stream_name = 5; + // string transmitter = 6; + + string title = 8; + string text = 9; + bytes attachment = 10; +} diff --git a/proto/response.pb.go b/proto/response.pb.go new file mode 100644 index 0000000..c95c194 --- /dev/null +++ b/proto/response.pb.go @@ -0,0 +1,229 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.30.0 +// protoc v3.12.4 +// source: response.proto + +package pb + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type TLDR int32 + +const ( + TLDR_TLDRInvalid TLDR = 0 + TLDR_TLDRSent TLDR = 1 + TLDR_TLDRQueued TLDR = 2 + TLDR_TLDRFailed TLDR = 3 +) + +// Enum value maps for TLDR. +var ( + TLDR_name = map[int32]string{ + 0: "TLDRInvalid", + 1: "TLDRSent", + 2: "TLDRQueued", + 3: "TLDRFailed", + } + TLDR_value = map[string]int32{ + "TLDRInvalid": 0, + "TLDRSent": 1, + "TLDRQueued": 2, + "TLDRFailed": 3, + } +) + +func (x TLDR) Enum() *TLDR { + p := new(TLDR) + *p = x + return p +} + +func (x TLDR) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (TLDR) Descriptor() protoreflect.EnumDescriptor { + return file_response_proto_enumTypes[0].Descriptor() +} + +func (TLDR) Type() protoreflect.EnumType { + return &file_response_proto_enumTypes[0] +} + +func (x TLDR) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use TLDR.Descriptor instead. +func (TLDR) EnumDescriptor() ([]byte, []int) { + return file_response_proto_rawDescGZIP(), []int{0} +} + +type Response struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Timestamp uint64 `protobuf:"varint,1,opt,name=timestamp,proto3" json:"timestamp,omitempty"` + Id string `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"` + Status int32 `protobuf:"varint,3,opt,name=status,proto3" json:"status,omitempty"` + Errors []string `protobuf:"bytes,4,rep,name=errors,proto3" json:"errors,omitempty"` // optional string receipt = 5; +} + +func (x *Response) Reset() { + *x = Response{} + if protoimpl.UnsafeEnabled { + mi := &file_response_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Response) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Response) ProtoMessage() {} + +func (x *Response) ProtoReflect() protoreflect.Message { + mi := &file_response_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Response.ProtoReflect.Descriptor instead. +func (*Response) Descriptor() ([]byte, []int) { + return file_response_proto_rawDescGZIP(), []int{0} +} + +func (x *Response) GetTimestamp() uint64 { + if x != nil { + return x.Timestamp + } + return 0 +} + +func (x *Response) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +func (x *Response) GetStatus() int32 { + if x != nil { + return x.Status + } + return 0 +} + +func (x *Response) GetErrors() []string { + if x != nil { + return x.Errors + } + return nil +} + +var File_response_proto protoreflect.FileDescriptor + +var file_response_proto_rawDesc = []byte{ + 0x0a, 0x0e, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x12, 0x08, 0x6f, 0x76, 0x65, 0x72, 0x70, 0x75, 0x73, 0x68, 0x22, 0x68, 0x0a, 0x08, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, + 0x61, 0x6d, 0x70, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, + 0x74, 0x61, 0x6d, 0x70, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x02, 0x69, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x03, + 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x16, 0x0a, 0x06, + 0x65, 0x72, 0x72, 0x6f, 0x72, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x09, 0x52, 0x06, 0x65, 0x72, + 0x72, 0x6f, 0x72, 0x73, 0x2a, 0x45, 0x0a, 0x04, 0x54, 0x4c, 0x44, 0x52, 0x12, 0x0f, 0x0a, 0x0b, + 0x54, 0x4c, 0x44, 0x52, 0x49, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x10, 0x00, 0x12, 0x0c, 0x0a, + 0x08, 0x54, 0x4c, 0x44, 0x52, 0x53, 0x65, 0x6e, 0x74, 0x10, 0x01, 0x12, 0x0e, 0x0a, 0x0a, 0x54, + 0x4c, 0x44, 0x52, 0x51, 0x75, 0x65, 0x75, 0x65, 0x64, 0x10, 0x02, 0x12, 0x0e, 0x0a, 0x0a, 0x54, + 0x4c, 0x44, 0x52, 0x46, 0x61, 0x69, 0x6c, 0x65, 0x64, 0x10, 0x03, 0x42, 0x06, 0x5a, 0x04, 0x2e, + 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_response_proto_rawDescOnce sync.Once + file_response_proto_rawDescData = file_response_proto_rawDesc +) + +func file_response_proto_rawDescGZIP() []byte { + file_response_proto_rawDescOnce.Do(func() { + file_response_proto_rawDescData = protoimpl.X.CompressGZIP(file_response_proto_rawDescData) + }) + return file_response_proto_rawDescData +} + +var file_response_proto_enumTypes = make([]protoimpl.EnumInfo, 1) +var file_response_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_response_proto_goTypes = []interface{}{ + (TLDR)(0), // 0: overpush.TLDR + (*Response)(nil), // 1: overpush.Response +} +var file_response_proto_depIdxs = []int32{ + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_response_proto_init() } +func file_response_proto_init() { + if File_response_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_response_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Response); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_response_proto_rawDesc, + NumEnums: 1, + NumMessages: 1, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_response_proto_goTypes, + DependencyIndexes: file_response_proto_depIdxs, + EnumInfos: file_response_proto_enumTypes, + MessageInfos: file_response_proto_msgTypes, + }.Build() + File_response_proto = out.File + file_response_proto_rawDesc = nil + file_response_proto_goTypes = nil + file_response_proto_depIdxs = nil +} diff --git a/proto/response.proto b/proto/response.proto new file mode 100644 index 0000000..47b7953 --- /dev/null +++ b/proto/response.proto @@ -0,0 +1,19 @@ +syntax = 'proto3'; +package overpush; + +option go_package = '.;pb'; + +enum TLDR { + TLDRInvalid = 0; + TLDRSent = 1; + TLDRQueued = 2; + TLDRFailed = 3; +} + +message Response { + uint64 timestamp = 1; + string id = 2; + int32 status = 3; + repeated string errors = 4; + // optional string receipt = 5; +} \ No newline at end of file diff --git a/proto/service.pb.go b/proto/service.pb.go new file mode 100644 index 0000000..5453d5a --- /dev/null +++ b/proto/service.pb.go @@ -0,0 +1,74 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.30.0 +// protoc v3.12.4 +// source: service.proto + +package pb + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +var File_service_proto protoreflect.FileDescriptor + +var file_service_proto_rawDesc = []byte{ + 0x0a, 0x0d, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, + 0x08, 0x6f, 0x76, 0x65, 0x72, 0x70, 0x75, 0x73, 0x68, 0x1a, 0x0d, 0x6d, 0x65, 0x73, 0x73, 0x61, + 0x67, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x0e, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x32, 0x43, 0x0a, 0x08, 0x4f, 0x76, 0x65, 0x72, + 0x70, 0x75, 0x73, 0x68, 0x12, 0x37, 0x0a, 0x0c, 0x51, 0x75, 0x65, 0x75, 0x65, 0x4d, 0x65, 0x73, + 0x73, 0x61, 0x67, 0x65, 0x12, 0x11, 0x2e, 0x6f, 0x76, 0x65, 0x72, 0x70, 0x75, 0x73, 0x68, 0x2e, + 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x1a, 0x12, 0x2e, 0x6f, 0x76, 0x65, 0x72, 0x70, 0x75, + 0x73, 0x68, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x06, 0x5a, + 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var file_service_proto_goTypes = []interface{}{ + (*Message)(nil), // 0: overpush.Message + (*Response)(nil), // 1: overpush.Response +} +var file_service_proto_depIdxs = []int32{ + 0, // 0: overpush.Overpush.QueueMessage:input_type -> overpush.Message + 1, // 1: overpush.Overpush.QueueMessage:output_type -> overpush.Response + 1, // [1:2] is the sub-list for method output_type + 0, // [0:1] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_service_proto_init() } +func file_service_proto_init() { + if File_service_proto != nil { + return + } + file_message_proto_init() + file_response_proto_init() + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_service_proto_rawDesc, + NumEnums: 0, + NumMessages: 0, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_service_proto_goTypes, + DependencyIndexes: file_service_proto_depIdxs, + }.Build() + File_service_proto = out.File + file_service_proto_rawDesc = nil + file_service_proto_goTypes = nil + file_service_proto_depIdxs = nil +} diff --git a/proto/service.proto b/proto/service.proto new file mode 100644 index 0000000..04ade7d --- /dev/null +++ b/proto/service.proto @@ -0,0 +1,11 @@ +syntax = 'proto3'; +package overpush; + +option go_package = '.;pb'; + +import 'message.proto'; +import 'response.proto'; + +service Overpush { + rpc QueueMessage(Message) returns (Response) {}; +} \ No newline at end of file diff --git a/proto/service_grpc.pb.go b/proto/service_grpc.pb.go new file mode 100644 index 0000000..e186632 --- /dev/null +++ b/proto/service_grpc.pb.go @@ -0,0 +1,109 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.3.0 +// - protoc v3.12.4 +// source: service.proto + +package pb + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +const ( + Overpush_QueueMessage_FullMethodName = "/overpush.Overpush/QueueMessage" +) + +// OverpushClient is the client API for Overpush service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type OverpushClient interface { + QueueMessage(ctx context.Context, in *Message, opts ...grpc.CallOption) (*Response, error) +} + +type overpushClient struct { + cc grpc.ClientConnInterface +} + +func NewOverpushClient(cc grpc.ClientConnInterface) OverpushClient { + return &overpushClient{cc} +} + +func (c *overpushClient) QueueMessage(ctx context.Context, in *Message, opts ...grpc.CallOption) (*Response, error) { + out := new(Response) + err := c.cc.Invoke(ctx, Overpush_QueueMessage_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// OverpushServer is the server API for Overpush service. +// All implementations must embed UnimplementedOverpushServer +// for forward compatibility +type OverpushServer interface { + QueueMessage(context.Context, *Message) (*Response, error) + mustEmbedUnimplementedOverpushServer() +} + +// UnimplementedOverpushServer must be embedded to have forward compatible implementations. +type UnimplementedOverpushServer struct { +} + +func (UnimplementedOverpushServer) QueueMessage(context.Context, *Message) (*Response, error) { + return nil, status.Errorf(codes.Unimplemented, "method QueueMessage not implemented") +} +func (UnimplementedOverpushServer) mustEmbedUnimplementedOverpushServer() {} + +// UnsafeOverpushServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to OverpushServer will +// result in compilation errors. +type UnsafeOverpushServer interface { + mustEmbedUnimplementedOverpushServer() +} + +func RegisterOverpushServer(s grpc.ServiceRegistrar, srv OverpushServer) { + s.RegisterService(&Overpush_ServiceDesc, srv) +} + +func _Overpush_QueueMessage_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(Message) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(OverpushServer).QueueMessage(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Overpush_QueueMessage_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(OverpushServer).QueueMessage(ctx, req.(*Message)) + } + return interceptor(ctx, in, info, handler) +} + +// Overpush_ServiceDesc is the grpc.ServiceDesc for Overpush service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var Overpush_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "overpush.Overpush", + HandlerType: (*OverpushServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "QueueMessage", + Handler: _Overpush_QueueMessage_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "service.proto", +}