63 lines
1.5 KiB
Go
63 lines
1.5 KiB
Go
|
package socketio
|
||
|
|
||
|
import "time"
|
||
|
|
||
|
type Options struct {
|
||
|
PingInterval time.Duration
|
||
|
PingTimeout time.Duration
|
||
|
ReceiveTimeout time.Duration
|
||
|
SendTimeout time.Duration
|
||
|
BufferSize int
|
||
|
}
|
||
|
|
||
|
type OptionFunc func(opts *Options)
|
||
|
|
||
|
func NewOptions(funcs ...OptionFunc) *Options {
|
||
|
opts := &Options{
|
||
|
PingInterval: 5 * time.Second,
|
||
|
PingTimeout: 60 * time.Second,
|
||
|
ReceiveTimeout: 60 * time.Second,
|
||
|
SendTimeout: 60 * time.Second,
|
||
|
BufferSize: 1024 * 32,
|
||
|
}
|
||
|
for _, fn := range funcs {
|
||
|
fn(opts)
|
||
|
}
|
||
|
return opts
|
||
|
}
|
||
|
|
||
|
// WithPingInterval configures the client to use the given ping interval
|
||
|
func WithPingInterval(interval time.Duration) OptionFunc {
|
||
|
return func(opts *Options) {
|
||
|
opts.PingInterval = interval
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// WithPingTimeout configures the client to use the given ping timeout
|
||
|
func WithPingTimeout(timeout time.Duration) OptionFunc {
|
||
|
return func(opts *Options) {
|
||
|
opts.PingTimeout = timeout
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// WithReceiveTimeout configures the client to use the given receive timeout
|
||
|
func WithReceiveTimeout(timeout time.Duration) OptionFunc {
|
||
|
return func(opts *Options) {
|
||
|
opts.ReceiveTimeout = timeout
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// WithSendTimeout configures the client to use the given send timeout
|
||
|
func WithSendTimeout(timeout time.Duration) OptionFunc {
|
||
|
return func(opts *Options) {
|
||
|
opts.SendTimeout = timeout
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// WithBufferSize configures the client to use the given buffer size
|
||
|
func WithBufferSize(size int) OptionFunc {
|
||
|
return func(opts *Options) {
|
||
|
opts.BufferSize = size
|
||
|
}
|
||
|
}
|