-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathglua.go
65 lines (53 loc) · 1.2 KB
/
glua.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
package glua
import (
"sync"
)
var (
globalOpts *Options
locker sync.Mutex
)
func init() {
globalOpts = NewOptions()
}
type Metric interface {
Counter(name string, value int64, labels map[string]string)
Gauge(name string, value int64, labels map[string]string)
}
type Options struct {
maxVmSize int
preloadScriptMethod func() string
metricHandle Metric
}
func NewOptions() *Options {
return &Options{
maxVmSize: 4,
}
}
func (opt *Options) WithMaxVMSize(maxVmSize int) *Options {
opt.maxVmSize = maxVmSize
return opt
}
func (opt *Options) SetPreloadScripeMethod(method func() string) *Options {
opt.preloadScriptMethod = method
return opt
}
func (opt *Options) SetMetric(handle Metric) *Options {
opt.metricHandle = handle
return opt
}
func GlobalOptions(opts *Options) {
locker.Lock()
defer locker.Unlock()
globalOpts = opts
}
// metric
func metricCounter(name string, value int64, labels map[string]string) {
if globalOpts.metricHandle != nil {
globalOpts.metricHandle.Counter(name, value, labels)
}
}
func metricGauge(name string, value int64, labels map[string]string) {
if globalOpts.metricHandle != nil {
globalOpts.metricHandle.Gauge(name, value, labels)
}
}