-
Notifications
You must be signed in to change notification settings - Fork 0
/
option.go
36 lines (30 loc) · 886 Bytes
/
option.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
package vbantxt
import (
"time"
log "github.com/sirupsen/logrus"
)
// Option is a functional option type that allows us to configure the VbanTxt.
type Option func(*VbanTxt)
// WithRateLimit is a functional option to set the ratelimit for requests
func WithRateLimit(ratelimit time.Duration) Option {
return func(vt *VbanTxt) {
vt.ratelimit = ratelimit
}
}
// WithBPSOpt is a functional option to set the bps index for {VbanTxt}.packet
func WithBPSOpt(bps int) Option {
return func(vt *VbanTxt) {
bpsIndex := indexOf(BpsOpts, bps)
if bpsIndex == -1 {
log.Warnf("invalid bps value %d, expected one of %v, defaulting to 0", bps, BpsOpts)
return
}
vt.packet.bpsIndex = bpsIndex
}
}
// WithChannel is a functional option to set the channel for {VbanTxt}.packet
func WithChannel(channel int) Option {
return func(vt *VbanTxt) {
vt.packet.channel = channel
}
}