39 lines
756 B
Go
39 lines
756 B
Go
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
|
|
}
|