Documentation ¶
Index ¶
- Constants
- Variables
- func GenCodeKey(p CommonParams) string
- func GenIPSourceLimitKey(p CommonParams) string
- func GenProviderLimitKey(p CommonParams) string
- func GenReceiverLimitKey(p CommonParams) string
- func GenSendLimitKey(p CommonParams) string
- func GenVerifyLimitKey(p CommonParams) string
- type BaseClient
- type Client
- type CodeParam
- type CommonParam
- type CommonParams
- type EmailClient
- type EmailClientPicker
- type MockClient
- type NotifyMethod
- type Option
- type Param
- type Params
- type SendParams
- type SmsClient
- type SmsClientPicker
- type VerifyParams
Constants ¶
const ( // KeyPrefixCode 验证码缓存 key 前缀 KeyPrefixCode = "micro.pkg:notify:code:" // KeyPrefixSendLimit 发送通知限制缓存 key 前缀 KeyPrefixSendLimit = "micro.pkg:notify:send.limit:" // KeyPrefixVerifyLimit 验证通知限制缓存 key 前缀 KeyPrefixVerifyLimit = "micro.pkg:notify:verify.limit:" // KeyPrefixReceiverLimit 接收方限制缓存 key 前缀 KeyPrefixReceiverLimit = "micro.pkg:notify:receiver.limit:" // KeyPrefixIPSourceLimit IP 来源限制缓存 key 前缀 KeyPrefixIPSourceLimit = "micro.pkg:notify:ip.source.limit:" // KeyPrefixProviderLimit 提供方限制缓存 key 前缀 KeyPrefixProviderLimit = "micro.pkg:notify:provider.limit:" )
Variables ¶
var ( // ErrInvalidParams 请求参数错误 ErrInvalidParams = errcode.ErrInvalidParams // ErrProviderOverQuota 提供方请求超过配额错误 ErrProviderOverQuota = bizerr.ErrProviderOverQuota // ErrIPSourceOverQuota IP 地址请求超过配额错误 ErrIPSourceOverQuota = bizerr.ErrIPSourceOverQuota // ErrReceiverOverQuota 接收方请求超过配额错误 ErrReceiverOverQuota = bizerr.ErrReceiverOverQuota // ErrSendTooFrequently 发送过于频繁错误 ErrSendTooFrequently = bizerr.ErrSendTooFrequently // ErrVerifyTooFrequently 验证过于频繁错误 ErrVerifyTooFrequently = bizerr.ErrVerifyTooFrequently // ErrEmailUnsupported 暂不支持邮件通知服务错误 ErrEmailUnsupported = bizerr.ErrEmailUnsupported // ErrSmsUnsupported 暂不支持短信通知服务错误 ErrSmsUnsupported = bizerr.ErrSmsUnsupported // ErrEmailTmplNotFound 邮件模板不存在错误 ErrEmailTmplNotFound = bizerr.ErrEmailTmplNotFound // ErrSmsTmplNotFound 短信模板不存在错误 ErrSmsTmplNotFound = bizerr.ErrSmsTmplNotFound // ErrInvalidCaptcha 验证码错误 ErrInvalidCaptcha = bizerr.ErrInvalidCaptcha // ErrCaptchaNotFound 验证码不存在或已过期错误 ErrCaptchaNotFound = bizerr.ErrCaptchaNotFound )
Functions ¶
func GenIPSourceLimitKey ¶
func GenIPSourceLimitKey(p CommonParams) string
GenIPSourceLimitKey 生成IP地址来源限制缓存 key
func GenProviderLimitKey ¶
func GenProviderLimitKey(p CommonParams) string
GenProviderLimitKey 生成提供方限制缓存 key
func GenReceiverLimitKey ¶
func GenReceiverLimitKey(p CommonParams) string
GenReceiverLimitKey 生成接收方限制缓存 key
func GenVerifyLimitKey ¶
func GenVerifyLimitKey(p CommonParams) string
GenVerifyLimitKey 生成验证通知限制缓存 key
Types ¶
type BaseClient ¶
type BaseClient struct { HTTPClient *http.Client // HTTP 客户端 // contains filtered or unexported fields }
BaseClient 基础客户端
func (*BaseClient) ParseEmailTmpl ¶
func (bc *BaseClient) ParseEmailTmpl(templateID string) string
ParseEmailTmpl 解析邮件对应模板
func (*BaseClient) ParseSmsTmpl ¶
func (bc *BaseClient) ParseSmsTmpl(templateID string) string
ParseSmsTmpl 解析短信对应模板
type CodeParam ¶
type CodeParam struct { Key string // 键 Value string // 值 Length int // 长度 Expiration time.Duration // 过期时间 }
CodeParam 验证码参数
type CommonParam ¶
CommonParam 通用参数
type CommonParams ¶
type CommonParams struct { NotifyMethod NotifyMethod // 通知方式(可以为 Sms 或 Email) IP string // IP 地址 Provider string // 提供方 Receiver string // 接受方 TemplateID string // 模板编号 }
CommonParams 通用通知参数
type EmailClient ¶
type EmailClient interface { Client // SendEmail 发送邮件 SendEmail(receiver, templateID string, params ...Param) error }
EmailClient 邮件客户端接口
type EmailClientPicker ¶
type EmailClientPicker interface { // Pick 选取一个邮件客户端 Pick() (ec EmailClient, key string, isExist bool) // Get 获取一个邮件客户端 Get(key string) (ec EmailClient, isExist bool) // Add 添加一个邮件客户端 Add(key string, value EmailClient) // Remove 移除一个邮件客户端 Remove(keys ...string) }
EmailClientPicker 邮件客户端选取器接口
func NewEmailClientPicker ¶
func NewEmailClientPicker() EmailClientPicker
NewEmailClientPicker 新建邮件客户端选取器
type MockClient ¶
type MockClient struct{}
MockClient 模拟短信、邮件客户端
type NotifyMethod ¶
type NotifyMethod int32
NotifyMethod 通知方式
const ( // Sms 通知方式:短信 Sms NotifyMethod = 0 // sms // Email 通知方式:邮件 Email NotifyMethod = 1 // email )
func NotifyMethodString ¶
func NotifyMethodString(s string) (NotifyMethod, error)
NotifyMethodString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.
func NotifyMethodValues ¶
func NotifyMethodValues() []NotifyMethod
NotifyMethodValues returns all values of the enum
func (NotifyMethod) IsANotifyMethod ¶
func (i NotifyMethod) IsANotifyMethod() bool
IsANotifyMethod returns "true" if the value is listed in the enum definition. "false" otherwise
func (NotifyMethod) MarshalJSON ¶
func (i NotifyMethod) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface for NotifyMethod
func (NotifyMethod) String ¶
func (i NotifyMethod) String() string
func (*NotifyMethod) UnmarshalJSON ¶
func (i *NotifyMethod) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface for NotifyMethod
type Option ¶
type Option func(bc *BaseClient)
Option 可选配置
func WithEmailTmplMap ¶
WithEmailTmplMap 使用邮件对应模板映射
type SendParams ¶
type SendParams struct { CommonParams // 通用通知参数 IsMock bool // 是否模拟发送 Params []Param // 参数列表 }
SendParams 发送通知参数
type SmsClient ¶
type SmsClient interface { Client // SendSms 发送短信 SendSms(receiver, templateID string, params ...Param) error }
SmsClient 短信客户端接口
type SmsClientPicker ¶
type SmsClientPicker interface { // Pick 选取一个短信客户端 Pick() (sc SmsClient, key string, isExist bool) // Get 获取一个短信客户端 Get(key string) (sc SmsClient, isExist bool) // Add 添加一个短信客户端 Add(key string, value SmsClient) // Remove 移除一个短信客户端 Remove(keys ...string) }
SmsClientPicker 短信客户端选取器接口
type VerifyParams ¶
type VerifyParams struct { CommonParams // 通用通知参数 Code string // 验证码 Clear bool // 验证成功后是否清除 }
VerifyParams 校验通知参数