/
sms_payloads.go
42 lines (32 loc) · 1.04 KB
/
sms_payloads.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package sms2fa
import (
"fmt"
"github.com/volatiletech/authboss"
)
// SMSValuer returns a code or a resend-code from the body
type SMSValuer interface {
authboss.Validator
GetCode() string
GetRecoveryCode() string
}
// SMSPhoneNumberValuer returns a phone number from the body
type SMSPhoneNumberValuer interface {
authboss.Validator
GetPhoneNumber() string
}
// MustHaveSMSValues upgrades a validatable set of values
// to one specifically holding the code we're looking for, or a resend.
func MustHaveSMSValues(v authboss.Validator) SMSValuer {
if u, ok := v.(SMSValuer); ok {
return u
}
panic(fmt.Sprintf("bodyreader returned a type that could not be upgraded to SMSValuer: %T", v))
}
// MustHaveSMSPhoneNumberValue upgrades a validatable set of values
// to ones specifically holding a phone number.
func MustHaveSMSPhoneNumberValue(v authboss.Validator) SMSPhoneNumberValuer {
if u, ok := v.(SMSPhoneNumberValuer); ok {
return u
}
panic(fmt.Sprintf("bodyreader returned a type that could not be upgraded to SMSValuer: %T", v))
}