/
domain.go
38 lines (31 loc) · 912 Bytes
/
domain.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
// Package domain provides domain-specific configuration.
package domain
import (
"context"
)
type ctxKey int
const (
ctxDomainConfig ctxKey = iota
ctxDomain
)
// CtxConfig contains domain-specific settings related to a request context.
type CtxConfig struct {
AllUsersGroupID int64
TempUsersGroupID int64
}
// ConfigItem is one item of the configuration list.
type ConfigItem struct {
Domains []string
AllUsersGroup int64
TempUsersGroup int64
}
// ConfigFromContext retrieves the current domain configuration from a context set by the middleware.
func ConfigFromContext(ctx context.Context) *CtxConfig {
conf := ctx.Value(ctxDomainConfig).(*CtxConfig)
confCopy := *conf
return &confCopy
}
// CurrentDomainFromContext retrieves the current domain from a context set by the middleware.
func CurrentDomainFromContext(ctx context.Context) string {
return ctx.Value(ctxDomain).(string)
}