-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
114 lines (97 loc) · 2.86 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package grpc_prom
import (
"github.com/gin-gonic/gin"
"github.com/prometheus/client_golang/prometheus/promhttp"
"net/http"
)
type RequestLabelMappingFn func(c *gin.Context) string
// Config defines the config for logger middleware
type config struct {
handlerUrl string
namespace string
name string
duration []float64
slowTime float64
excludeRegexCode []string
excludeRegexRpcType []string
excludeRegexServiceName []string
excludeRegexMethodName []string
endpointLabelMappingFn RequestLabelMappingFn
counterOpts []CounterOption
}
// Option for queue system
type Option func(*config)
// WithNamespace set namespace function
func WithNamespace(namespace string) Option {
return func(cfg *config) {
cfg.namespace = namespace
}
}
// WithName set name function
func WithName(name string) Option {
return func(cfg *config) {
cfg.name = name
}
}
// WithHandlerUrl set handlerUrl function
func WithHandlerUrl(handlerUrl string) Option {
return func(cfg *config) {
cfg.handlerUrl = handlerUrl
}
}
// WithExcludeRegexRpcType set excludeRegexRpcType function regexp
func WithExcludeRegexRpcType(excludeRegexRpcType []string) Option {
return func(cfg *config) {
cfg.excludeRegexRpcType = excludeRegexRpcType
}
}
// WithExcludeRegexRegexServiceName set excludeRegexServiceName function regexp
func WithExcludeRegexRegexServiceName(excludeRegexServiceName []string) Option {
return func(cfg *config) {
cfg.excludeRegexServiceName = excludeRegexServiceName
}
}
// WithExcludeRegexMethodName set excludeRegexMethodName function regexp
func WithExcludeRegexMethodName(excludeRegexMethodName []string) Option {
return func(cfg *config) {
cfg.excludeRegexMethodName = excludeRegexMethodName
}
}
// WithExcludeRegexCode set excludeRegexCode function regexp
func WithExcludeRegexCode(excludeRegexCode []string) Option {
return func(cfg *config) {
cfg.excludeRegexCode = excludeRegexCode
}
}
// WithEndpointLabelMappingFn set endpointLabelMappingFn function
func WithEndpointLabelMappingFn(endpointLabelMappingFn RequestLabelMappingFn) Option {
return func(cfg *config) {
cfg.endpointLabelMappingFn = endpointLabelMappingFn
}
}
//WithPromHandler set router function
func WithPromHandler(r *http.ServeMux) Option {
return func(cfg *config) {
if r != nil {
r.Handle(cfg.handlerUrl, promhttp.Handler())
}
}
}
// WithDuration set duration function 0.1, 0.3, 1.2, 5
func WithDuration(duration []float64) Option {
return func(cfg *config) {
cfg.duration = duration
}
}
// WithSlowTime set slowTime function 1
func WithSlowTime(slowTime float64) Option {
return func(cfg *config) {
cfg.slowTime = slowTime
}
}
// WithCounterOption set counterOpts function 1
func WithCounterOption(counterOpts []CounterOption) Option {
return func(cfg *config) {
cfg.counterOpts = counterOpts
}
}