-
Notifications
You must be signed in to change notification settings - Fork 0
/
flags.go
41 lines (35 loc) · 1.02 KB
/
flags.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
package target
type Flags uint64
const (
FlagPre Flags = 1 << iota
FlagAbs
FlagCors
FlagSecureMode
FlagForwardHost
FlagForwardAddr
FlagIgnoreCert
)
var (
routeFlagMask = FlagPre | FlagAbs | FlagCors | FlagSecureMode | FlagForwardHost | FlagForwardAddr | FlagIgnoreCert
redirectFlagMask = FlagPre | FlagAbs
)
// HasFlag returns true if the bits contain the requested flag
func (f Flags) HasFlag(flag Flags) bool {
// 0110 & 0100 == 0100 (value != 0 thus true)
// 0011 & 0100 == 0000 (value == 0 thus false)
return f&flag != 0
}
// NormaliseRouteFlags returns only the bits used for routes
func (f Flags) NormaliseRouteFlags() Flags {
// removes bits outside the mask
// 0110 & 0111 == 0110
// 1010 & 0111 == 0010 (values are different)
return f & routeFlagMask
}
// NormaliseRedirectFlags returns only the bits used for redirects
func (f Flags) NormaliseRedirectFlags() Flags {
// removes bits outside the mask
// 0110 & 0111 == 0110
// 1010 & 0111 == 0010 (values are different)
return f & redirectFlagMask
}