From afd6b215d6b686a39c406ceae88cf487d1eca2d6 Mon Sep 17 00:00:00 2001 From: Nguyen Minh Date: Thu, 23 Mar 2023 10:34:58 +0700 Subject: [PATCH] reqrep socket --- client/socket.go | 21 +++++++++++++++++++++ model/socket.go | 9 +++++++++ subject/config.go | 2 ++ subject/socket.go | 14 ++++++++++++++ 4 files changed, 46 insertions(+) create mode 100644 client/socket.go create mode 100644 model/socket.go create mode 100644 subject/socket.go diff --git a/client/socket.go b/client/socket.go new file mode 100644 index 0000000..6c0a125 --- /dev/null +++ b/client/socket.go @@ -0,0 +1,21 @@ +package client + +import ( + "git.selly.red/Selly-Modules/natsio" + "git.selly.red/Selly-Modules/natsio/model" + "git.selly.red/Selly-Modules/natsio/subject" +) + +// Socket ... +type Socket struct{} + +// GetSocket ... +func GetSocket() Socket { + return Socket{} +} + +// EmitSocketEventDataReward ... +func (s Socket) EmitSocketEventDataReward(p model.PayloadEmitSocketEvent) error { + _, err := natsio.GetServer().Request(subject.Socket.EmitEventReward, toBytes(p)) + return err +} diff --git a/model/socket.go b/model/socket.go new file mode 100644 index 0000000..6271383 --- /dev/null +++ b/model/socket.go @@ -0,0 +1,9 @@ +package model + +// PayloadEmitSocketEvent ... +type PayloadEmitSocketEvent struct { + User string `json:"user"` + Message string `json:"message"` + Data string `json:"data"` + IsNotRemove bool `json:"isNotRemove"` +} diff --git a/subject/config.go b/subject/config.go index 0ba5952..d319a6f 100644 --- a/subject/config.go +++ b/subject/config.go @@ -18,6 +18,7 @@ var prefixes = struct { Queue string Campaign string Affiliate string + Socket string }{ Communication: "communication", Order: "order", @@ -36,4 +37,5 @@ var prefixes = struct { Queue: "queue", Campaign: "campaign", Affiliate: "affiliate", + Socket: "socket", } diff --git a/subject/socket.go b/subject/socket.go new file mode 100644 index 0000000..dae77c1 --- /dev/null +++ b/subject/socket.go @@ -0,0 +1,14 @@ +package subject + +import "fmt" + +func getSocketValue(val string) string { + return fmt.Sprintf("%s.%s", prefixes.Socket, val) +} + +// Socket ... +var Socket = struct { + EmitEventReward string +}{ + EmitEventReward: getSocketValue("emit_event_reward"), +}