Documentation
¶
Index ¶
- Constants
- func DedupKey(messageID string) string
- func ResolveThreadID(req *WebhookRequest) string
- type DedupMode
- type DedupReleaser
- type Deduplicator
- type Handler
- type HandlerOption
- func WithAdmitTimeout(d time.Duration) HandlerOption
- func WithContext(ctx context.Context) HandlerOption
- func WithDedupMode(mode DedupMode) HandlerOption
- func WithDedupTTL(d time.Duration) HandlerOption
- func WithDedupTimeout(d time.Duration) HandlerOption
- func WithDeduplicator(d Deduplicator) HandlerOption
- func WithDurableAdmission(admitter MessageAdmitter) HandlerOption
- func WithEnqueueTimeout(d time.Duration) HandlerOption
- func WithHandlerTimeout(d time.Duration) HandlerOption
- func WithMaxBodyBytes(n int64) HandlerOption
- func WithMetrics(m Metrics) HandlerOption
- func WithNonceCache(store Deduplicator) HandlerOption
- func WithOrderingMode(mode OrderingMode) HandlerOption
- func WithQueueSize(n int) HandlerOption
- func WithReplayWindow(d time.Duration) HandlerOption
- func WithTaskPool(pool TaskPool) HandlerOption
- func WithWebhookLogger(logger *slog.Logger) HandlerOption
- func WithWebhookSecret(secret string) HandlerOption
- func WithWebhookToken(token string) HandlerOption
- func WithWorkerCount(n int) HandlerOption
- type HandlerOptions
- type Message
- type MessageAdmitter
- type MessageHandler
- type MessageJSON
- type Metrics
- type NoopDeduplicator
- type NoopMetrics
- func (NoopMetrics) ObserveAccepted()
- func (NoopMetrics) ObserveBadRequest()
- func (NoopMetrics) ObserveDecodeLatency(_ time.Duration)
- func (NoopMetrics) ObserveDedupLatency(_ time.Duration)
- func (NoopMetrics) ObserveDuplicate()
- func (NoopMetrics) ObserveEnqueueFailure()
- func (NoopMetrics) ObserveEnqueueWait(_ time.Duration)
- func (NoopMetrics) ObserveHandlerDuration(_ time.Duration)
- func (NoopMetrics) ObserveQueueDepth(_ int)
- func (NoopMetrics) ObserveRequest()
- func (NoopMetrics) ObserveUnauthorized()
- type OrderingMode
- type ReceiveDiagnostics
- type SDKConfig
- type TaskPool
- type WebhookMention
- type WebhookRequest
Constants ¶
const ( PathWebhook = "/webhook/iris" HeaderIrisToken = "X-Iris-Token" HeaderIrisMessageID = irishmac.HeaderIrisMessageID HeaderIrisRoute = "X-Iris-Route" HeaderIrisSignatureVersion = irishmac.HeaderIrisSignatureVersion SignatureVersionV2 = irishmac.SignatureVersionV2 HeaderIrisTimestamp = irishmac.HeaderIrisTimestamp HeaderIrisNonce = irishmac.HeaderIrisNonce HeaderIrisSignature = irishmac.HeaderIrisSignature HeaderIrisBodySHA256 = irishmac.HeaderIrisBodySHA256 )
const DefaultDedupTTL = 60 * time.Second
Variables ¶
This section is empty.
Functions ¶
func ResolveThreadID ¶
func ResolveThreadID(req *WebhookRequest) string
Types ¶
type DedupReleaser ¶ added in v0.30.0
type Deduplicator ¶
type Deduplicator interface {
IsDuplicate(ctx context.Context, key string, ttl time.Duration) (bool, error)
}
Deduplicator는 중복 webhook 메시지를 검사하는 인터페이스입니다.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler는 stripe 워커 풀을 갖춘 webhook HTTP 핸들러입니다.
func NewHandler ¶
func NewHandler( ctx context.Context, token string, handler MessageHandler, logger *slog.Logger, opts ...HandlerOption, ) *Handler
func (*Handler) CloseContext ¶ added in v0.29.0
CloseContext는 grace context가 끝나면 queued callback을 건너뛰고 in-flight context를 취소한다.
func (*Handler) Diagnostics ¶
func (h *Handler) Diagnostics() ReceiveDiagnostics
type HandlerOption ¶
type HandlerOption func(*Handler)
func WithAdmitTimeout ¶ added in v0.30.0
func WithAdmitTimeout(d time.Duration) HandlerOption
func WithContext ¶
func WithContext(ctx context.Context) HandlerOption
func WithDedupMode ¶
func WithDedupMode(mode DedupMode) HandlerOption
WithDedupMode is retained for source compatibility. Deduplication always happens after authentication, body decoding, request validation, and message identity reconciliation. DedupModeBeforeDecode is no longer honored because a side-effecting backend could otherwise reserve an authenticated message ID for a request that is later rejected.
func WithDedupTTL ¶
func WithDedupTTL(d time.Duration) HandlerOption
func WithDedupTimeout ¶
func WithDedupTimeout(d time.Duration) HandlerOption
func WithDeduplicator ¶
func WithDeduplicator(d Deduplicator) HandlerOption
func WithDurableAdmission ¶ added in v0.29.0
func WithDurableAdmission(admitter MessageAdmitter) HandlerOption
WithDurableAdmission은 in-memory scheduler 대신 동기 durable admission을 사용한다.
func WithEnqueueTimeout ¶
func WithEnqueueTimeout(d time.Duration) HandlerOption
func WithHandlerTimeout ¶
func WithHandlerTimeout(d time.Duration) HandlerOption
func WithMaxBodyBytes ¶
func WithMaxBodyBytes(n int64) HandlerOption
func WithMetrics ¶
func WithMetrics(m Metrics) HandlerOption
func WithNonceCache ¶ added in v0.28.0
func WithNonceCache(store Deduplicator) HandlerOption
func WithOrderingMode ¶
func WithOrderingMode(mode OrderingMode) HandlerOption
func WithQueueSize ¶
func WithQueueSize(n int) HandlerOption
func WithReplayWindow ¶ added in v0.28.0
func WithReplayWindow(d time.Duration) HandlerOption
func WithTaskPool ¶
func WithTaskPool(pool TaskPool) HandlerOption
func WithWebhookLogger ¶
func WithWebhookLogger(logger *slog.Logger) HandlerOption
func WithWebhookSecret ¶ added in v0.28.0
func WithWebhookSecret(secret string) HandlerOption
func WithWebhookToken ¶
func WithWebhookToken(token string) HandlerOption
func WithWorkerCount ¶
func WithWorkerCount(n int) HandlerOption
type HandlerOptions ¶
type Message ¶
type Message struct {
Msg string `json:"msg"`
Room string `json:"room"`
Sender *string `json:"sender,omitempty"`
JSON *MessageJSON `json:"json,omitempty"`
}
type MessageAdmitter ¶ added in v0.29.0
MessageAdmitter는 HTTP 200 전에 메시지를 durable store에 commit하는 계약이다.
type MessageHandler ¶
MessageHandler는 수신된 webhook 메시지를 처리하는 인터페이스입니다.
type MessageJSON ¶
type MessageJSON struct {
UserID string `json:"user_id,omitempty"`
Message string `json:"message,omitempty"`
ChatID string `json:"chat_id,omitempty"`
Type string `json:"type,omitempty"`
Route string `json:"route,omitempty"`
MessageID string `json:"message_id,omitempty"`
ChatLogID string `json:"chat_log_id,omitempty"`
RoomType string `json:"room_type,omitempty"`
RoomLinkID string `json:"room_link_id,omitempty"`
SourceLogID *int64 `json:"source_log_id,omitempty"`
RawSourceLogID *int64 `json:"raw_source_log_id,omitempty"`
SourceGenerationID *int64 `json:"source_generation_id,omitempty"`
SourceAccountID string `json:"source_account_id,omitempty"`
ThreadID *string `json:"thread_id,omitempty"`
ThreadScope *int `json:"thread_scope,omitempty"`
IsMine *bool `json:"is_mine,omitempty"`
Origin string `json:"origin,omitempty"`
Attachment string `json:"attachment,omitempty"`
Mentions []WebhookMention `json:"mentions,omitempty"`
EventPayload json.RawMessage `json:"event_payload,omitempty"`
}
type Metrics ¶
type Metrics interface {
ObserveRequest()
ObserveBadRequest()
ObserveDuplicate()
ObserveEnqueueFailure()
ObserveAccepted()
ObserveDecodeLatency(d time.Duration)
ObserveDedupLatency(d time.Duration)
ObserveEnqueueWait(d time.Duration)
ObserveQueueDepth(depth int)
ObserveHandlerDuration(d time.Duration)
}
Metrics는 webhook 핸들러 메트릭 관측 포인트를 정의합니다.
type NoopMetrics ¶
type NoopMetrics struct{}
func (NoopMetrics) ObserveAccepted ¶
func (NoopMetrics) ObserveAccepted()
func (NoopMetrics) ObserveBadRequest ¶
func (NoopMetrics) ObserveBadRequest()
func (NoopMetrics) ObserveDecodeLatency ¶
func (NoopMetrics) ObserveDecodeLatency(_ time.Duration)
func (NoopMetrics) ObserveDedupLatency ¶
func (NoopMetrics) ObserveDedupLatency(_ time.Duration)
func (NoopMetrics) ObserveDuplicate ¶
func (NoopMetrics) ObserveDuplicate()
func (NoopMetrics) ObserveEnqueueFailure ¶
func (NoopMetrics) ObserveEnqueueFailure()
func (NoopMetrics) ObserveEnqueueWait ¶
func (NoopMetrics) ObserveEnqueueWait(_ time.Duration)
func (NoopMetrics) ObserveHandlerDuration ¶
func (NoopMetrics) ObserveHandlerDuration(_ time.Duration)
func (NoopMetrics) ObserveQueueDepth ¶
func (NoopMetrics) ObserveQueueDepth(_ int)
func (NoopMetrics) ObserveRequest ¶
func (NoopMetrics) ObserveRequest()
func (NoopMetrics) ObserveUnauthorized ¶
func (NoopMetrics) ObserveUnauthorized()
type OrderingMode ¶
type OrderingMode int
const ( OrderingModeKey OrderingMode = iota OrderingModeNone )
type ReceiveDiagnostics ¶
type ReceiveDiagnostics struct {
WorkersConfigured int `json:"workersConfigured"`
QueueSize int `json:"queueSize"`
Pending int `json:"pending"`
InFlight int `json:"inFlight"`
EnqueueRejected uint64 `json:"enqueueRejected"`
QueueFullCount uint64 `json:"queueFullCount"`
HandlerTimeouts uint64 `json:"handlerTimeoutCount"`
}
type SDKConfig ¶
func ResolveSDKConfig ¶
func ResolveSDKConfig(opts []HandlerOption) SDKConfig
type WebhookMention ¶
type WebhookMention struct {
UserID string `json:"userId"`
Nickname string `json:"nickname,omitempty"`
At []int `json:"at,omitempty"`
Len int `json:"len,omitempty"`
}
func (*WebhookMention) UnmarshalJSON ¶
func (m *WebhookMention) UnmarshalJSON(data []byte) error
type WebhookRequest ¶
type WebhookRequest struct {
Route string `json:"route,omitempty"`
MessageID string `json:"messageId,omitempty"`
SourceLogID int64 `json:"sourceLogId,omitempty"`
RawSourceLogID *int64 `json:"rawSourceLogId,omitempty"`
SourceGenerationID *int64 `json:"sourceGenerationId,omitempty"`
SourceAccountID string `json:"sourceAccountId,omitempty"`
Text string `json:"text"`
Room string `json:"room"`
Sender string `json:"sender"`
UserID string `json:"userId"`
ChatLogID string `json:"chatLogId,omitempty"`
RoomType string `json:"roomType,omitempty"`
RoomLinkID string `json:"roomLinkId,omitempty"`
ThreadID string `json:"threadId,omitempty"`
ThreadScope *int `json:"threadScope,omitempty"`
Type string `json:"type,omitempty"`
IsMine *bool `json:"isMine,omitempty"`
Origin string `json:"origin,omitempty"`
Attachment string `json:"attachment,omitempty"`
Mentions []WebhookMention `json:"mentions,omitempty"`
EventPayload json.RawMessage `json:"eventPayload,omitempty"`
}