Skip to content

Commit

Permalink
cr: golang style
Browse files Browse the repository at this point in the history
Signed-off-by: Max Englander <max@planetscale.com>
  • Loading branch information
maxenglander committed Feb 22, 2025
1 parent bb30d44 commit 110f3b8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions go/vt/discovery/healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ type HealthCheckImpl struct {
loadTabletsTrigger chan struct{}
// options contains optional settings used to modify HealthCheckImpl
// behavior.
options discoveryOptions
options Options
}

// NewVTGateHealthCheckFilters returns healthcheck filters for vtgate.
Expand Down Expand Up @@ -357,7 +357,7 @@ func NewVTGateHealthCheckFilters() (filters TabletFilters, err error) {
//
// Is one or more filters to apply when determining what tablets we want to stream healthchecks from.
func NewHealthCheck(
ctx context.Context, retryDelay, healthCheckTimeout time.Duration, topoServer *topo.Server, localCell, cellsToWatch string, filters TabletFilter, opts ...DiscoveryOption,
ctx context.Context, retryDelay, healthCheckTimeout time.Duration, topoServer *topo.Server, localCell, cellsToWatch string, filters TabletFilter, opts ...Option,
) *HealthCheckImpl {
hc := &HealthCheckImpl{
ts: topoServer,
Expand Down
36 changes: 18 additions & 18 deletions go/vt/discovery/discovery_options.go → go/vt/discovery/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,51 +17,51 @@ import (
"vitess.io/vitess/go/vt/logutil"
)

// discoveryOptions configure a discovery components. discoveryOptions are set
// by the DiscoveryOption values passed to the component constructors.
type discoveryOptions struct {
// Options configure a discovery components. Options are set by the Option
// values passed to the component constructors.
type Options struct {
logger logutil.Logger
}

// DiscoveryOption configures how we perform certain operations.
type DiscoveryOption interface {
apply(*discoveryOptions)
// Option configures how we perform certain operations.
type Option interface {
apply(*Options)
}

// funcDiscoveryOption wraps a function that modifies discoveryOptions into
// an implementation of the DiscoveryOption interface.
type funcDiscoveryOption struct {
f func(*discoveryOptions)
// funcOption wraps a function that modifies options into an implementation of
// the Option interface.
type funcOption struct {
f func(*Options)
}

func defaultOptions() discoveryOptions {
return discoveryOptions{
func defaultOptions() Options {
return Options{
logger: logutil.NewConsoleLogger(),
}
}

func withOptions(dos ...DiscoveryOption) discoveryOptions {
func withOptions(dos ...Option) Options {
os := defaultOptions()
for _, do := range dos {
do.apply(&os)
}
return os
}

func (fhco *funcDiscoveryOption) apply(dos *discoveryOptions) {
func (fhco *funcOption) apply(dos *Options) {
fhco.f(dos)
}

func newFuncDiscoveryOption(f func(*discoveryOptions)) *funcDiscoveryOption {
return &funcDiscoveryOption{
func newFuncOption(f func(*Options)) *funcOption {
return &funcOption{
f: f,
}
}

// WithLogger accepts a custom logger to use in a discovery component. If this
// option is not provided then the default system logger will be used.
func WithLogger(l logutil.Logger) DiscoveryOption {
return newFuncDiscoveryOption(func(o *discoveryOptions) {
func WithLogger(l logutil.Logger) Option {
return newFuncOption(func(o *Options) {
o.logger = l
})
}
10 changes: 5 additions & 5 deletions go/vt/discovery/topology_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ type TopologyWatcher struct {
firstLoadChan chan struct{}
// options contains optional settings used to modify HealthCheckImpl
// behavior.
options discoveryOptions
options Options
}

// NewTopologyWatcher returns a TopologyWatcher that monitors all
// the tablets in a cell, and reloads them as needed.
func NewTopologyWatcher(
ctx context.Context, topoServer *topo.Server, hc HealthCheck, f TabletFilter, cell string, refreshInterval time.Duration, refreshKnownTablets bool, opts ...DiscoveryOption,
ctx context.Context, topoServer *topo.Server, hc HealthCheck, f TabletFilter, cell string, refreshInterval time.Duration, refreshKnownTablets bool, opts ...Option,
) *TopologyWatcher {
tw := &TopologyWatcher{
topoServer: topoServer,
Expand Down Expand Up @@ -299,7 +299,7 @@ type FilterByShard struct {
filters map[string][]*filterShard
// options contains optional settings used to modify FilterByShard
// behavior.
options discoveryOptions
options Options
}

// filterShard describes a filter for a given shard or keyrange inside
Expand All @@ -308,15 +308,15 @@ type filterShard struct {
keyspace string
shard string
keyRange *topodatapb.KeyRange // only set if shard is also a KeyRange
options discoveryOptions
options Options
}

// NewFilterByShard creates a new FilterByShard for use by a
// TopologyWatcher. Each filter is a keyspace|shard entry, where shard
// can either be a shard name, or a keyrange. All tablets that match
// at least one keyspace|shard tuple will be forwarded by the
// TopologyWatcher to its consumer.
func NewFilterByShard(filters []string, opts ...DiscoveryOption) (*FilterByShard, error) {
func NewFilterByShard(filters []string, opts ...Option) (*FilterByShard, error) {
m := make(map[string][]*filterShard)
for _, filter := range filters {
parts := strings.Split(filter, "|")
Expand Down

0 comments on commit 110f3b8

Please sign in to comment.