Add reach.Option comments

This commit is contained in:
wpetit 2018-09-19 10:01:28 +02:00
parent cd27332c4f
commit 68371cb7c7
1 changed files with 11 additions and 0 deletions

View File

@ -8,6 +8,7 @@ import (
"forge.cadoles.com/Pyxis/golang-socketio" "forge.cadoles.com/Pyxis/golang-socketio"
) )
// Logger is a logger implementation for the ReachRS client
type Logger interface { type Logger interface {
Printf(format string, args ...interface{}) Printf(format string, args ...interface{})
} }
@ -23,50 +24,59 @@ type Options struct {
Logger Logger Logger Logger
} }
// OptionFunc is an option configuration for the ReachRS client
type OptionFunc func(opts *Options) type OptionFunc func(opts *Options)
// WithEndpoint configures the client to target the given host and port
func WithEndpoint(host string, port int) OptionFunc { func WithEndpoint(host string, port int) OptionFunc {
return func(opts *Options) { return func(opts *Options) {
opts.Endpoint = gosocketio.GetUrl(host, port, false) opts.Endpoint = gosocketio.GetUrl(host, port, false)
} }
} }
// WithPingInterval configures the client to use the given ping interval
func WithPingInterval(interval time.Duration) OptionFunc { func WithPingInterval(interval time.Duration) OptionFunc {
return func(opts *Options) { return func(opts *Options) {
opts.PingInterval = interval opts.PingInterval = interval
} }
} }
// WithPingTimeout configures the client to use the given ping timeout
func WithPingTimeout(timeout time.Duration) OptionFunc { func WithPingTimeout(timeout time.Duration) OptionFunc {
return func(opts *Options) { return func(opts *Options) {
opts.PingTimeout = timeout opts.PingTimeout = timeout
} }
} }
// WithReceiveTimeout configures the client to use the given receive timeout
func WithReceiveTimeout(timeout time.Duration) OptionFunc { func WithReceiveTimeout(timeout time.Duration) OptionFunc {
return func(opts *Options) { return func(opts *Options) {
opts.ReceiveTimeout = timeout opts.ReceiveTimeout = timeout
} }
} }
// WithSendTimeout configures the client to use the given send timeout
func WithSendTimeout(timeout time.Duration) OptionFunc { func WithSendTimeout(timeout time.Duration) OptionFunc {
return func(opts *Options) { return func(opts *Options) {
opts.SendTimeout = timeout opts.SendTimeout = timeout
} }
} }
// WithBufferSize configures the client to use the given buffer size
func WithBufferSize(size int) OptionFunc { func WithBufferSize(size int) OptionFunc {
return func(opts *Options) { return func(opts *Options) {
opts.BufferSize = size opts.BufferSize = size
} }
} }
// WithLogger configures the client to use the given logger
func WithLogger(logger Logger) OptionFunc { func WithLogger(logger Logger) OptionFunc {
return func(opts *Options) { return func(opts *Options) {
opts.Logger = logger opts.Logger = logger
} }
} }
// WithStandardLogger configures the client to use the given standard logger
func WithStandardLogger() OptionFunc { func WithStandardLogger() OptionFunc {
return func(opts *Options) { return func(opts *Options) {
logger := log.New(os.Stdout, "[reachrs] ", log.LstdFlags) 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 { func DefaultOptions() *Options {
opts := &Options{} opts := &Options{}
defaults := []OptionFunc{ defaults := []OptionFunc{