From 035fb59f64829bbf99edf93af0d937793393d0e3 Mon Sep 17 00:00:00 2001 From: Tue Date: Thu, 17 Nov 2022 13:55:44 +0700 Subject: [PATCH] build email --- client/email.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 client/email.go diff --git a/client/email.go b/client/email.go new file mode 100644 index 0000000..0de10e1 --- /dev/null +++ b/client/email.go @@ -0,0 +1,38 @@ +package client + +import ( + "encoding/json" + "errors" + "git.selly.red/Selly-Modules/natsio" + "git.selly.red/Selly-Modules/natsio/model" + "git.selly.red/Selly-Modules/natsio/subject" +) + +// Email ... +type Email struct{} + +// GetEmail ... +func GetEmail() Email { + return Email{} +} + +func (s Email) Send(p model.GetEmailRequest) ([]*model.ResponseEmailInfo, error) { + msg, err := natsio.GetServer().Request(subject.Email.GetListEmailInfo, toBytes(p)) + if err != nil { + return nil, err + } + + var r struct { + Data []*model.ResponseEmailInfo `json:"data"` + Error string `json:"error"` + } + + if err := json.Unmarshal(msg.Data, &r); err != nil { + return nil, err + } + if r.Error != "" { + return nil, errors.New(r.Error) + } + + return r.Data, nil +}