From cd2c326efa4efd69510289201faa1cd2274c4b2d Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sat, 26 Oct 2024 23:30:52 +0800 Subject: [PATCH] :sparkles: Pushcon SDK --- go.mod | 1 + go.sum | 2 ++ pkg/pushkit/pushcon/conn.go | 42 +++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 pkg/pushkit/pushcon/conn.go diff --git a/go.mod b/go.mod index f4b40e7..10b22a7 100644 --- a/go.mod +++ b/go.mod @@ -12,6 +12,7 @@ require ( github.com/nats-io/nats.go v1.37.0 github.com/robfig/cron/v3 v3.0.1 github.com/rs/zerolog v1.33.0 + github.com/samber/lo v1.47.0 github.com/sideshow/apns2 v0.24.0 github.com/spf13/viper v1.19.0 google.golang.org/api v0.171.0 diff --git a/go.sum b/go.sum index e299591..1fa6da3 100644 --- a/go.sum +++ b/go.sum @@ -279,6 +279,8 @@ github.com/sagikazarmark/locafero v0.6.0 h1:ON7AQg37yzcRPU69mt7gwhFEBwxI6P9T4Qu3 github.com/sagikazarmark/locafero v0.6.0/go.mod h1:77OmuIc6VTraTXKXIs/uvUxKGUXjE1GbemJYHqdNjX0= github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE= github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ= +github.com/samber/lo v1.47.0 h1:z7RynLwP5nbyRscyvcD043DWYoOcYRv3mV8lBeqOCLc= +github.com/samber/lo v1.47.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 h1:nn5Wsu0esKSJiIVhscUtVbo7ada43DJhG55ua/hjS5I= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= github.com/sideshow/apns2 v0.24.0 h1:syofL4rd8ZeqUVySgYyBSYr/oLMU/HzJi++r3FIp6Z4= diff --git a/pkg/pushkit/pushcon/conn.go b/pkg/pushkit/pushcon/conn.go new file mode 100644 index 0000000..a182c2c --- /dev/null +++ b/pkg/pushkit/pushcon/conn.go @@ -0,0 +1,42 @@ +package pushcon + +import ( + "git.solsynth.dev/hypernet/nexus/pkg/nex" + "git.solsynth.dev/hypernet/nexus/pkg/nex/rx" + "git.solsynth.dev/hypernet/pusher/pkg/pushkit" +) + +type Conn struct { + n *nex.Conn + mq *rx.MqConn +} + +func NewConn(conn *nex.Conn) (*Conn, error) { + c := &Conn{ + n: conn, + } + + if mq, err := rx.NewMqConn(conn); err != nil { + return nil, err + } else { + c.mq = mq + } + + return c, nil +} + +func (v *Conn) PushNotify(in pushkit.NotificationPushRequest) error { + return v.mq.Nt.Publish(pushkit.PushNotificationMqTopic, nex.EncodeMap(in)) +} + +func (v *Conn) PushNotifyBatch(in pushkit.NotificationPushBatchRequest) error { + return v.mq.Nt.Publish(pushkit.PushNotificationBatchMqTopic, nex.EncodeMap(in)) +} + +func (v *Conn) PushEmail(in pushkit.EmailDeliverRequest) error { + return v.mq.Nt.Publish(pushkit.PushEmailMqTopic, nex.EncodeMap(in)) +} + +func (v *Conn) PushEmailBatch(in pushkit.EmailDeliverBatchRequest) error { + return v.mq.Nt.Publish(pushkit.PushEmailBatchMqTopic, nex.EncodeMap(in)) +}