reqrep socket

This commit is contained in:
Nguyen Minh 2023-03-23 10:34:58 +07:00
parent 71d674b74c
commit afd6b215d6
4 changed files with 46 additions and 0 deletions

21
client/socket.go Normal file
View File

@ -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
}

9
model/socket.go Normal file
View File

@ -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"`
}

View File

@ -18,6 +18,7 @@ var prefixes = struct {
Queue string Queue string
Campaign string Campaign string
Affiliate string Affiliate string
Socket string
}{ }{
Communication: "communication", Communication: "communication",
Order: "order", Order: "order",
@ -36,4 +37,5 @@ var prefixes = struct {
Queue: "queue", Queue: "queue",
Campaign: "campaign", Campaign: "campaign",
Affiliate: "affiliate", Affiliate: "affiliate",
Socket: "socket",
} }

14
subject/socket.go Normal file
View File

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