mirror of
https://github.com/bensema/gotdx.git
synced 2025-11-21 02:45:33 +08:00
新增options来配置
This commit is contained in:
34
options.go
Normal file
34
options.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package gotdx
|
||||
|
||||
const (
|
||||
_defaultTCPAddress = "119.147.212.81:7709"
|
||||
_defaultRetryTimes = 3
|
||||
)
|
||||
|
||||
type Options struct {
|
||||
TCPAddress string // 服务器地址
|
||||
MaxRetryTimes int // 重试次数
|
||||
}
|
||||
|
||||
func defaultOptions() *Options {
|
||||
return &Options{
|
||||
TCPAddress: _defaultTCPAddress,
|
||||
MaxRetryTimes: _defaultRetryTimes,
|
||||
}
|
||||
}
|
||||
|
||||
func applyOptions(opts ...Option) *Options {
|
||||
o := defaultOptions()
|
||||
for _, opt := range opts {
|
||||
opt(o)
|
||||
}
|
||||
return o
|
||||
}
|
||||
|
||||
type Option func(options *Options)
|
||||
|
||||
func WithTCPAddress(tcpAddress string) Option {
|
||||
return func(o *Options) {
|
||||
o.TCPAddress = tcpAddress
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user