forked from ory/kratos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontext.go
49 lines (36 loc) · 1.23 KB
/
context.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
47
48
49
package corp
import (
"context"
"net/http"
"github.com/gofrs/uuid"
"github.com/ory/kratos/driver/config"
)
type Contextualizer interface {
ContextualizeTableName(ctx context.Context, name string) string
ContextualizeMiddleware(ctx context.Context) func(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc)
ContextualizeConfig(ctx context.Context, fb *config.Config) *config.Config
ContextualizeNID(ctx context.Context, fallback uuid.UUID) uuid.UUID
}
var c Contextualizer = nil
func GetContextualizer() Contextualizer {
return c
}
func SetContextualizer(cc Contextualizer) {
if _, ok := cc.(*ContextNoOp); ok && c != nil {
return
}
c = cc
}
// These global functions call the respective method on Context
func ContextualizeTableName(ctx context.Context, name string) string {
return c.ContextualizeTableName(ctx, name)
}
func ContextualizeMiddleware(ctx context.Context) func(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
return c.ContextualizeMiddleware(ctx)
}
func ContextualizeConfig(ctx context.Context, fb *config.Config) *config.Config {
return c.ContextualizeConfig(ctx, fb)
}
func ContextualizeNID(ctx context.Context, fallback uuid.UUID) uuid.UUID {
return c.ContextualizeNID(ctx, fallback)
}