Documentation
¶
Index ¶
- func SubscriptionIDToTopic(id SubscriptionID) (string, error)
- type InMemoryCache
- type Manager
- type Subscription
- type SubscriptionID
- type SubscriptionManager
- type SubscriptionRequest
- type TwitchError
- type TwitchWebhookHandler
- func (m *TwitchWebhookHandler) Subscribe(request SubscriptionRequest, denialCallback func(reason string)) (err error)
- func (m *TwitchWebhookHandler) SubscriptionCallbackHandler() http.HandlerFunc
- func (m *TwitchWebhookHandler) Unsubscribe(topic string) error
- func (m *TwitchWebhookHandler) ValidateSignature(r *http.Request) (bool, io.Reader, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SubscriptionIDToTopic ¶
func SubscriptionIDToTopic(id SubscriptionID) (string, error)
SubscriptionIDToTopic converts an id to a topic
Types ¶
type InMemoryCache ¶
type InMemoryCache struct {
// contains filtered or unexported fields
}
InMemoryCache caches subscriptions
func (*InMemoryCache) Delete ¶
func (c *InMemoryCache) Delete(topic string) error
Delete removes a subscription
func (*InMemoryCache) Get ¶
func (c *InMemoryCache) Get(topic string) (*Subscription, error)
Get retrieves a subscription
func (*InMemoryCache) Save ¶
func (c *InMemoryCache) Save(topic string, sub *Subscription) error
Save caches a subscription, returns an error if a subscription already exists
func (*InMemoryCache) SetSubscriptionLease ¶
SetSubscriptionLease retrieves a subscription
type Manager ¶
type Manager interface {
SubscriptionCallbackHandler() http.HandlerFunc
Subscribe(req SubscriptionRequest, deniedCallback func(reason string)) error
Unsubscribe(topic string) error
ValidateSignature(*http.Request) (valid bool, body io.Reader, err error)
}
Manager takes care of webhooks
type Subscription ¶
type Subscription struct {
Topic string
CallbackURL string
Lease time.Duration
Secret string
DenialCallback func(reason string)
Renew func()
}
Subscription is a cache item
type SubscriptionID ¶
type SubscriptionID string
SubscriptionID describes an id
func NewSubscriptionID ¶
func NewSubscriptionID(topic string) (SubscriptionID, error)
NewSubscriptionID generates a random subscription id using topic
type SubscriptionManager ¶
type SubscriptionManager interface {
Delete(topic string) error
Get(topic string) (*Subscription, error)
Save(topic string, sub *Subscription) error
SetSubscriptionLease(topic string, lease time.Duration) (exists bool, err error)
}
SubscriptionManager manages subscription state
type SubscriptionRequest ¶
SubscriptionRequest contains parameters for a subscription
type TwitchError ¶
type TwitchError struct {
Err string `json:"error"`
Status int64 `json:"status"`
Message string `json:"message"`
}
TwitchError is the api message format for errors
func (TwitchError) Error ¶
func (e TwitchError) Error() string
type TwitchWebhookHandler ¶
type TwitchWebhookHandler struct {
Manager SubscriptionManager
OAuth2ClientID string
OAuth2ClientSecret string
Logger *zap.Logger
// contains filtered or unexported fields
}
TwitchWebhookHandler is an implementation for twitch webhooks
func (*TwitchWebhookHandler) Subscribe ¶
func (m *TwitchWebhookHandler) Subscribe(request SubscriptionRequest, denialCallback func(reason string)) (err error)
Subscribe subscribes the webhook
func (*TwitchWebhookHandler) SubscriptionCallbackHandler ¶
func (m *TwitchWebhookHandler) SubscriptionCallbackHandler() http.HandlerFunc
SubscriptionCallbackHandler handles websub requests
func (*TwitchWebhookHandler) Unsubscribe ¶
func (m *TwitchWebhookHandler) Unsubscribe(topic string) error
Unsubscribe unsubscribes the webhook
func (*TwitchWebhookHandler) ValidateSignature ¶
ValidateSignature validates the notification using the subscription's secret