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"), +}