Versions in this module Expand all Collapse all v0 v0.38.0 Nov 8, 2026 Changes in this version + const DefaultMaxDrift + var ErrBadSignature = errors.New("webhook: 签名不匹配") + var ErrMissingSignature = errors.New("webhook: 验签 header 缺失") + var ErrStaleTimestamp = errors.New("webhook: 时间戳缺失/非法/超出容忍窗") + var ErrUnknownPlatform = errors.New("webhook: 平台未注册") + type HMACOption func(*HMACValidator) + func WithBase64() HMACOption + func WithFallbackHeaders(names ...string) HMACOption + func WithSignaturePrefix(prefix string) HMACOption + type HMACValidator struct + func NewForgejoValidator(secret []byte) *HMACValidator + func NewGitHubValidator(secret []byte) *HMACValidator + func NewGiteaValidator(secret []byte) *HMACValidator + func NewHMACValidator(secret []byte, algo crypto.Hash, header string, opts ...HMACOption) *HMACValidator + func (v *HMACValidator) Validate(r *http.Request, body []byte) error + type Registry struct + func NewRegistry() *Registry + func (rg *Registry) Platforms() []string + func (rg *Registry) Register(platform string, v Validator) + func (rg *Registry) Validate(platform string, r *http.Request, body []byte) error + func (rg *Registry) Validator(platform string) (Validator, bool) + type StaticTokenValidator struct + func NewStaticTokenValidator(header string, token []byte) *StaticTokenValidator + func (v *StaticTokenValidator) Validate(r *http.Request, body []byte) error + type TimestampHMACValidator struct + func NewTimestampHMACValidator(secret []byte, algo crypto.Hash, tsName, sigName string, ...) *TimestampHMACValidator + func (v *TimestampHMACValidator) Validate(r *http.Request, body []byte) error + type TimestampOption func(*TimestampHMACValidator) + func WithClock(now func() time.Time) TimestampOption + func WithMaxDrift(d time.Duration) TimestampOption + func WithMessage(fn func(timestamp string, body []byte) []byte) TimestampOption + func WithQuerySource() TimestampOption + func WithURLEncoded() TimestampOption + type Validator interface + Validate func(r *http.Request, body []byte) error + func Fallback(validators ...Validator) Validator + func NewGitCodeValidator(secret []byte, staticToken []byte) Validator + func NewGiteeValidator(secret []byte, password []byte, opts ...TimestampOption) Validator + type ValidatorFunc func(r *http.Request, body []byte) error + func (f ValidatorFunc) Validate(r *http.Request, body []byte) error