-
Notifications
You must be signed in to change notification settings - Fork 12
/
interceptor.go
46 lines (36 loc) · 1.61 KB
/
interceptor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package fiber
import (
"context"
)
// CtxKey is an alias for a string and is used to associate keys to context objects
type CtxKey string
var (
// CtxComponentIDKey is used to denote the component's id in the request context
CtxComponentIDKey CtxKey = "CTX_COMPONENT_ID"
// CtxComponentKindKey is used to denote the component's kind in the request context
CtxComponentKindKey CtxKey = "CTX_COMPONENT_KIND"
// CtxComponentLabelsKey is used to denote the component's labels in the request context
CtxComponentLabelsKey CtxKey = "CTX_COMPONENT_LABELS"
)
// Interceptor is the interface for a structural interceptor
type Interceptor interface {
BeforeDispatch(ctx context.Context, req Request) context.Context
AfterDispatch(ctx context.Context, req Request, queue ResponseQueue)
AfterCompletion(ctx context.Context, req Request, queue ResponseQueue)
}
// NoopBeforeDispatchInterceptor does no operations before dispatch
type NoopBeforeDispatchInterceptor struct{}
// BeforeDispatch is an empty method
func (i *NoopBeforeDispatchInterceptor) BeforeDispatch(ctx context.Context, req Request) context.Context {
return ctx
}
// NoopAfterDispatchInterceptor does no operations after dispatch
type NoopAfterDispatchInterceptor struct{}
// AfterDispatch is an empty method
func (i *NoopAfterDispatchInterceptor) AfterDispatch(context.Context, Request, ResponseQueue) {
}
// NoopAfterCompletionInterceptor does no operations after request completion
type NoopAfterCompletionInterceptor struct{}
// AfterCompletion is an empty method
func (i *NoopAfterCompletionInterceptor) AfterCompletion(context.Context, Request, ResponseQueue) {
}