Merge branch 'build-auth-sms' of git.selly.red:Selly-Modules/natsio into develop

This commit is contained in:
Tue 2022-11-17 13:56:08 +07:00
commit d293fb7412
1 changed files with 38 additions and 0 deletions

38
client/email.go Normal file
View File

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