natsio/client/authsms.go

39 lines
796 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"
)
// AuthSMS ...
type AuthSMS struct{}
// GetAutSMS ...
func GetAutSMS() AuthSMS {
return AuthSMS{}
}
func (s AuthSMS) CreateUserSMSViaAuthSMS(p model.CreateUserSMSRequest) (*model.CreateUserSMSResponse, error) {
msg, err := natsio.GetServer().Request(subject.AuthSMS.CreateUserSMS, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Data *model.CreateUserSMSResponse `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
}