diff --git a/reach/option.go b/reach/option.go index 516cf45..80a713c 100644 --- a/reach/option.go +++ b/reach/option.go @@ -8,6 +8,7 @@ import ( "forge.cadoles.com/Pyxis/golang-socketio" ) +// Logger is a logger implementation for the ReachRS client type Logger interface { Printf(format string, args ...interface{}) } @@ -23,50 +24,59 @@ type Options struct { Logger Logger } +// OptionFunc is an option configuration for the ReachRS client type OptionFunc func(opts *Options) +// WithEndpoint configures the client to target the given host and port func WithEndpoint(host string, port int) OptionFunc { return func(opts *Options) { opts.Endpoint = gosocketio.GetUrl(host, port, false) } } +// 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 } } +// WithLogger configures the client to use the given logger func WithLogger(logger Logger) OptionFunc { return func(opts *Options) { opts.Logger = logger } } +// WithStandardLogger configures the client to use the given standard logger func WithStandardLogger() OptionFunc { return func(opts *Options) { logger := log.New(os.Stdout, "[reachrs] ", log.LstdFlags) @@ -74,6 +84,7 @@ func WithStandardLogger() OptionFunc { } } +// DefaultOptions returns the default values for the client options func DefaultOptions() *Options { opts := &Options{} defaults := []OptionFunc{