webhook

package
v0.32.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: Apache-2.0 Imports: 19 Imported by: 2

Documentation

Index

Constants

View Source
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
)
View Source
const DefaultDedupTTL = 60 * time.Second

Variables

This section is empty.

Functions

func DedupKey

func DedupKey(messageID string) string

DedupKey는 주어진 메시지 ID로 중복 제거 키를 생성합니다. messageID가 비어 있으면 빈 문자열을 반환합니다.

func ResolveThreadID

func ResolveThreadID(req *WebhookRequest) string

Types

type DedupMode

type DedupMode int
const (
	DedupModeBeforeDecode DedupMode = iota
	DedupModeAfterDecode
)

type DedupReleaser added in v0.30.0

type DedupReleaser interface {
	Release(ctx context.Context, key string) error
}

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) Close

func (h *Handler) Close() error

Close는 admission을 닫고 모든 작업이 끝날 때까지 기다리는 호환 wrapper입니다.

func (*Handler) CloseContext added in v0.29.0

func (h *Handler) CloseContext(ctx context.Context) error

CloseContext는 grace context가 끝나면 queued callback을 건너뛰고 in-flight context를 취소한다.

func (*Handler) Diagnostics

func (h *Handler) Diagnostics() ReceiveDiagnostics

func (*Handler) ServeHTTP

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

ServeHTTP는 Iris webhook 요청을 처리합니다.

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 HandlerOptions struct {
	WorkerCount    int
	QueueSize      int
	EnqueueTimeout time.Duration
	AdmitTimeout   time.Duration
	HandlerTimeout time.Duration
	OrderingMode   OrderingMode
	DedupTTL       time.Duration
	DedupTimeout   time.Duration
	DedupMode      DedupMode
	MaxBodyBytes   int64
}

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

type MessageAdmitter interface {
	AdmitMessage(ctx context.Context, msg *Message) error
}

MessageAdmitter는 HTTP 200 전에 메시지를 durable store에 commit하는 계약이다.

type MessageHandler

type MessageHandler interface {
	HandleMessage(ctx context.Context, msg *Message)
}

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()
	ObserveUnauthorized()
	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 NoopDeduplicator

type NoopDeduplicator struct{}

func (NoopDeduplicator) IsDuplicate

func (NoopDeduplicator) IsDuplicate(_ context.Context, _ string, _ time.Duration) (bool, error)

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

type SDKConfig struct {
	Token  string
	Secret string
	Logger *slog.Logger
	Ctx    context.Context
}

func ResolveSDKConfig

func ResolveSDKConfig(opts []HandlerOption) SDKConfig

type TaskPool

type TaskPool interface {
	SubmitWait(task func()) bool
}

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"`
}

Jump to

Keyboard shortcuts

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