qingniao

package
v1.1.6 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

README

qingniao(青鸟)

功能

提供通知服务,支持

  • Http:基于Http的通知,提供一个端点即可
    • JWT:基于JWT验证的通知
  • Voice:基于语音的通知(电话)
  • SMS:基于短信的通知
  • EMail:基于邮件的通知

为什么叫青鸟

中国古代神话中的神鸟,色泽亮丽、体态轻盈。传说为女神西王母的使者,共三只。又称三鸟。三青鸟是凤凰的前身,本为多力健飞的猛禽,后渐传为色泽亮丽,体态轻盈的小鸟,是具有神性的吉祥之物。汉代画像砖上常见于西王母座侧

传说西王母驾临前,总有青鸟先来报信,『青鸟不传云外信,丁香空结雨中愁』(南唐中主山花子),文学上,青鸟是被当作传递信息的使者。后人将它视为传递幸福佳音的使者

而使者就是传信的意思,和Notify不谋而和

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrorNotSupportNotify = &gox.CodeError{ErrorCode: 102, Message: "不支持的通知类型"}

ErrorNotSupportNotify 不支持的通知类型

Functions

This section is empty.

Types

type Client

type Client struct {
	class100.Client

	// Endpoint 地址
	Endpoint string `default:"https://qingniao.class100.com" json:"endpoint"`
}

Client 青鸟客户端

func New

func New(endpoint string, accessKey string, secretKey string) *Client

New 创建一个新的青鸟客户端

func (*Client) Notify

func (c *Client) Notify(notify *Notify, environment core.Environment, version class100.ApiVersion) (rsp Response, err error)

func (Client) String

func (c Client) String() string

type Email

type Email struct {
	// Subject 标题
	Subject string `json:"subject" validate:"required"`
	// CCs 抄送人员列表
	CCs []string `json:"ccs" validate:"dive,email"`
	// BCCs 密送人员列表
	BCCs []string `json:"bccs" validate:"dive,email"`
	// To 需要发送的手机号
	To string `json:"to" validate:"required,email"`
}

Email 邮件通知

func (Email) String

func (e Email) String() string

type Http

type Http struct {
	// Url 通信地址
	Url string `json:"url" validate:"required"`
	// Headers 请求头
	Headers map[string]string `json:"headers"`
}

Http Http通知

func (Http) String

func (h Http) String() string

type Notifier

type Notifier interface {
	// Notify 发送通知
	Notify(data interface{}) (err error)
}

Notifier

type Notify

type Notify struct {
	// Type 通知类型
	Type NotifyType `default:"http" json:"type" validate:"required,oneof=http voice sms email"`
	// MaxRetry 最大重试次数
	MaxRetry int `default:"6" json:"maxRetry" validate:"omitempty,min=1,max=100"`
	// Notifier 真正的通知者
	Notifier interface{} `json:"notifier" validate:"required"`
	// Data 数据
	Data interface{} `json:"data"`
}

Notify 回调通知

func NewEmailNotify

func NewEmailNotify(to string, maxRetry int, data interface{}) *Notify

NewEmailNotify 创建新的邮件通知

func NewHttpNotify

func NewHttpNotify(url string, headers map[string]string, maxRetry int, data interface{}) *Notify

NewHttpNotify 创建新的Http通知

func NewJWTNotify

func NewJWTNotify(url string, scheme string, token string, maxRetry int, data interface{}) *Notify

NewJWTNotify 创建新的JWT通知

func NewNotify

func NewNotify(notifyType NotifyType, maxRetry int, notifier interface{}, data interface{}) *Notify

NewNotify 创建一个新的通知

func NewSimpleJWTNotify

func NewSimpleJWTNotify(url string, scheme string, token string) *Notify

NewSimpleJWTNotify 创建简单JWT通知

func NewSimpleNotify

func NewSimpleNotify(notifyType NotifyType, notifier interface{}, data interface{}) *Notify

NewSimpleNotify 创建简单的通知

func NewSmsNotify

func NewSmsNotify(to string, maxRetry int, data interface{}) *Notify

NewSmsNotify 创建新的短信通知

func NewVoiceNotify

func NewVoiceNotify(to string, maxRetry int, data interface{}) *Notify

NewVoiceNotify 创建新的语音通知

func (Notify) String

func (n Notify) String() string

func (*Notify) UnmarshalJSON

func (n *Notify) UnmarshalJSON(data []byte) (err error)

type NotifyType

type NotifyType string

NotifyType 通知类型

const (
	// NotifyTypeHttp Http通知
	NotifyTypeHttp NotifyType = "http"
	// NotifyTypeVoice 语音通知
	NotifyTypeVoice NotifyType = "voice"
	// NotifyTypeSMS 短信通知
	NotifyTypeSms NotifyType = "sms"
	// NotifyTypeEmail 邮件通知
	NotifyTypeEmail NotifyType = "email"
)

type Request

type Request struct {
	class100.Request

	// Notify 请求
	Notify *Notify `json:"notify" validate:"required,structonly"`
}

Request 青鸟请求

func (Request) String

func (r Request) String() string

type Response

type Response struct {
	// 编号
	Id string `json:"id"`
	// 关键信息
	Key string `json:"key"`
}

Response 响应

func (Response) String

func (r Response) String() string

type Sms

type Sms struct {
	// To 需要发送的手机号
	To string `json:"to" validate:"required"`
}

Sms 短信通知

func (Sms) String

func (s Sms) String() string

type Voice

type Voice struct {
	// To 需要发送的手机号
	To string `json:"to" validate:"required"`
}

Voice 语音通知

func (Voice) String

func (v Voice) String() string

Jump to

Keyboard shortcuts

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