webhook

package
v0.0.0-...-deab030 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package webhook 包含订阅事件相关功能, 主要功能由 Handler 提供

Index

Constants

This section is empty.

Variables

View Source
var (
	PayloadTypeURLVerification = "url_verification"
	PayloadTypeEventCallback   = "event_callback"
)

Functions

func RegistEv

func RegistEv(typ string, newEv func() interface{})

RegistEv 注册一种订阅事件类型,typ 是 payload["event"]["type"] 字段, newEv 是工厂函数, 用于创建一个新的该类型事件

Types

type Handler

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

Handler 是一个 http.Handler,用于处理订阅事件回调/自动处理 url_verification, 同时它也满足 AppTicketProvider, 可为应用商店应用提供 app ticket

func New

func New(cnf conf.WebhookConfig, handler PayloadHandler) *Handler

New 创建一个 Handler,cnf 必须提供,handler 可用于处理感兴趣的事件, 也可以传入 nil

func (*Handler) FeishuAppTicket

func (h *Handler) FeishuAppTicket() (string, error)

FeishuAppTicket 满足 AppTicketProvider 接口

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP 满足 http.Handler 接口

type Payload

type Payload struct {
	// Type 是类型: event_callback-事件推送,url_verification-url地址验证
	Type string `json:"type"`

	// Token 即 Verification Token
	Token string `json:"token"`

	// Challenge 需要原样返回. type 为 url_verification 时有
	Challenge string `json:"challenge"`

	// Timestamp 是事件发送时间,一般近似于事件发生的时间. type 为 event_callback 时有
	Timestamp string `json:"ts"`

	// UUID 是事件的唯一标识, 主要用于保证幂等性. type 为 event_callback 时有
	UUID string `json:"uuid"`

	// RawEvent 是未解析的事件内容. type 为 event_callback 时有
	RawEvent json.RawMessage `json:"event"`
	// contains filtered or unexported fields
}

Payload 是订阅事件的 payload

func (*Payload) GetEvent

func (payload *Payload) GetEvent() interface{}

GetEvent 返回事件,仅当 type 是 event_callback 时返回非 nil

type PayloadHandler

type PayloadHandler func(w http.ResponseWriter, r *http.Request, payload *Payload)

PayloadHandler 用于处理 webhook payload

Directories

Path Synopsis
Package events 包含各种订阅事件类型 TODO: event 类型未完整
Package events 包含各种订阅事件类型 TODO: event 类型未完整

Jump to

Keyboard shortcuts

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