-
Notifications
You must be signed in to change notification settings - Fork 2
/
options.go
73 lines (64 loc) · 1.8 KB
/
options.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package gotcha
import "sync/atomic"
// units definition coppied from https://github.com/alecthomas/units
//nolint
const (
Kibibyte int64 = 1024
KiB = Kibibyte
Mebibyte = Kibibyte * 1024
MiB = Mebibyte
Gibibyte = Mebibyte * 1024
GiB = Gibibyte
Tebibyte = Gibibyte * 1024
TiB = Tebibyte
Pebibyte = Tebibyte * 1024
PiB = Pebibyte
Exbibyte = Pebibyte * 1024
EiB = Exbibyte
)
//nolint
const (
Kilobyte int64 = 1000
KB = Kilobyte
Megabyte = Kilobyte * 1000
MB = Megabyte
Gigabyte = Megabyte * 1000
GB = Gigabyte
Terabyte = Gigabyte * 1000
TB = Terabyte
Petabyte = Terabyte * 1000
PB = Petabyte
Exabyte = Petabyte * 1000
EB = Exabyte
)
//nolint
const (
Kilo int64 = 1000
Mega = Kilo * 1000
Giga = Mega * 1000
Tera = Giga * 1000
Peta = Tera * 1000
Exa = Peta * 1000
Infinity = -1
)
// ContextOpt defines gotcha context limit options
// that could be applied to gotchactx.
type ContextOpt func(*gotchactx)
// ContextWithLimitBytes defines allocation limit bytes gotcha context option.
func ContextWithLimitBytes(lbytes int64) ContextOpt {
return func(ctx *gotchactx) {
atomic.StoreInt64(&ctx.lbytes, lbytes)
}
}
// ContextWithLimitObjects defines allocation limit objects gotcha context option.
func ContextWithLimitObjects(lobjects int64) ContextOpt {
return func(ctx *gotchactx) {
atomic.StoreInt64(&ctx.lobjects, lobjects)
}
}
// ContextWithLimitCalls defines allocation limit calls gotcha context option.
func ContextWithLimitCalls(lcalls int64) ContextOpt {
return func(ctx *gotchactx) {
atomic.StoreInt64(&ctx.lcalls, lcalls)
}
}