notification

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

func Do(hosts []string, req *http.Request) (*http.Response, error)

随机请求hosts其中之一,得到一个通讯成功的应答

func NewULID

func NewULID() ulid.ULID

Types

type Message

type Message struct {
	ExpiredAt   time.Time `gorm:"not null; index:idx_retry;"`
	Hosts       string    `gorm:"not null; type:varchar(255);"`
	Path        string    `gorm:"not null; type:varchar(255);"`
	Method      string    `gorm:"type:varchar(255);"` //默认使用POST
	ContentType string    `gorm:"type:varchar(255);"` //默认使用application/json
	Data        []byte
}

type Notifier

type Notifier struct {
	// contains filtered or unexported fields
}

func NewNotifier

func NewNotifier(db *gorm.DB, options Options) (*Notifier, error)

func (*Notifier) NewNotifierMessage

func (n *Notifier) NewNotifierMessage(message Message) (*NotifierMessage, error)

func (*Notifier) Notify

func (n *Notifier) Notify(m *NotifierMessage) (*http.Response, error)

通知消息

type NotifierMessage

type NotifierMessage struct {
	ID          string     `gorm:"primaryKey; type:varchar(255);"`
	ServiceName string     `gorm:"index:idx_retry; type:varchar(255);"`
	SuccessAt   *time.Time `gorm:"index:idx_retry"`
	Message     `gorm:"embedded"`
	FailCount   int `gorm:"type:int(11);"`
	CreatedAt   time.Time
	UpdatedAt   time.Time
}

func (NotifierMessage) TableName

func (NotifierMessage) TableName() string

TableName overrides the table name used by Message to `yi_notifier_messages`

type Options

type Options struct {
	ServiceName string
	Validate    //验证http应答是否合法,不合法的将轮询重试请求
	context.Context
	PollingInterval    time.Duration //轮询间隔
	DefaultContentType string
	DefaultMethod      string
}

type Validate

type Validate func(*http.Response) error

Jump to

Keyboard shortcuts

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