fleet/server/datastore/mysql/config.go

33 lines
750 B
Go
Raw Normal View History

package mysql
2016-08-28 03:59:17 +00:00
import "github.com/go-kit/kit/log"
2016-08-28 03:59:17 +00:00
const defaultMaxAttempts int = 15
2016-08-28 03:59:17 +00:00
// DBOption is used to pass optional arguments to a database connection
type DBOption func(o *dbOptions) error
type dbOptions struct {
// maxAttempts configures the number of retries to connect to the DB
maxAttempts int
logger log.Logger
2016-08-28 03:59:17 +00:00
}
// Logger adds a logger to the datastore
func Logger(l log.Logger) DBOption {
2016-08-28 03:59:17 +00:00
return func(o *dbOptions) error {
o.logger = l
return nil
}
}
// LimitAttempts sets a the number of attempts
// to try establishing a connection to the database backend
// the default value is 15 attempts
func LimitAttempts(attempts int) DBOption {
return func(o *dbOptions) error {
o.maxAttempts = attempts
return nil
}
}