natsio/client/auth_sms.go

38 lines
666 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{}
// GetAuthSMS ...
func GetAuthSMS() AuthSMS {
return AuthSMS{}
}
func (s AuthSMS) CheckPermission(p model.CheckPermissionRequest) error {
msg, err := natsio.GetServer().Request(subject.AuthSMS.CheckPermission, toBytes(p))
if err != nil {
return err
}
var r struct {
Error string `json:"error"`
}
if err = json.Unmarshal(msg.Data, &r); err != nil {
return err
}
if r.Error != "" {
return errors.New(r.Error)
}
return nil
}