types

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 11, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
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 GenCodeKey

func GenCodeKey(p CommonParams) string

GenCodeKey 生成验证码缓存 key

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 GenSendLimitKey

func GenSendLimitKey(p CommonParams) string

GenSendLimitKey 生成发送通知限制缓存 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 NewBaseClient

func NewBaseClient(opts ...Option) *BaseClient

NewBaseClient 新建基础客户端

func (*BaseClient) ParseEmailTmpl

func (bc *BaseClient) ParseEmailTmpl(templateID string) string

ParseEmailTmpl 解析邮件对应模板

func (*BaseClient) ParseSmsTmpl

func (bc *BaseClient) ParseSmsTmpl(templateID string) string

ParseSmsTmpl 解析短信对应模板

type Client

type Client interface {
	// Platform 服务平台
	Platform() string
}

Client 客户端接口

type CodeParam

type CodeParam struct {
	Key        string        // 键
	Value      string        // 值
	Length     int           // 长度
	Expiration time.Duration // 过期时间
}

CodeParam 验证码参数

func (*CodeParam) GetKey

func (p *CodeParam) GetKey() string

GetKey 获取参数键

func (*CodeParam) GetValue

func (p *CodeParam) GetValue() string

GetValue 获取参数值

func (*CodeParam) IsEmpty

func (p *CodeParam) IsEmpty() bool

IsEmpty 判断是否为空

type CommonParam

type CommonParam struct {
	Key   string // 键
	Value string // 值
}

CommonParam 通用参数

func (*CommonParam) GetKey

func (p *CommonParam) GetKey() string

GetKey 获取参数键

func (*CommonParam) GetValue

func (p *CommonParam) GetValue() string

GetValue 获取参数值

type CommonParams

type CommonParams struct {
	NotifyMethod NotifyMethod // 通知方式(可以为 Sms 或 Email)
	IP           string       // IP 地址
	Provider     string       // 提供方
	Receiver     string       // 接受方
	TemplateID   string       // 模板编号
}

CommonParams 通用通知参数

func (CommonParams) IsValid

func (p CommonParams) IsValid() bool

IsValid 判断参数是否合法

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 模拟短信、邮件客户端

func (*MockClient) Platform

func (c *MockClient) Platform() string

Platform 服务平台

func (*MockClient) SendEmail

func (c *MockClient) SendEmail(receiver, templateID string, params ...Param) error

SendEmail 发送邮件

func (*MockClient) SendSms

func (c *MockClient) SendSms(receiver, templateID string, params ...Param) error

SendSms 发送短信

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

func WithEmailTmplMap(m map[string]string) Option

WithEmailTmplMap 使用邮件对应模板映射

func WithHTTPClient

func WithHTTPClient(hc *http.Client) Option

WithHTTPClient 使用 HTTP 客户端

func WithSmsTmplMap

func WithSmsTmplMap(m map[string]string) Option

WithSmsTmplMap 使用短信对应模板映射

type Param

type Param interface {
	GetKey() string   // 获取参数键
	GetValue() string // 获取参数值
}

Param 参数接口

type Params

type Params []Param

Params 参数列表

func (Params) Keys

func (ps Params) Keys() []string

Keys 获取参数列表所有键

func (Params) ToMap

func (ps Params) ToMap() map[string]string

ToMap 将参数列表转换成 map

func (Params) Values

func (ps Params) Values() []string

Values 获取参数列表所有值

type SendParams

type SendParams struct {
	CommonParams         // 通用通知参数
	IsMock       bool    // 是否模拟发送
	Params       []Param // 参数列表
}

SendParams 发送通知参数

func (*SendParams) IsValid

func (p *SendParams) IsValid() bool

IsValid 判断参数是否合法

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 短信客户端选取器接口

func NewSmsClientPicker

func NewSmsClientPicker() SmsClientPicker

NewSmsClientPicker 新建短信客户端选取器

type VerifyParams

type VerifyParams struct {
	CommonParams        // 通用通知参数
	Code         string // 验证码
	Clear        bool   // 验证成功后是否清除
}

VerifyParams 校验通知参数

func (*VerifyParams) IsValid

func (p *VerifyParams) IsValid() bool

IsValid 判断参数是否合法

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL