Skip to content

Commit

Permalink
func name changes and comments added
Browse files Browse the repository at this point in the history
  • Loading branch information
ktkenny committed Jan 23, 2024
1 parent b021bdb commit 541ff6b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
12 changes: 3 additions & 9 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,11 @@ func (c *Config) SetMetricsInterval(dur time.Duration) {
c.metricsInterval = dur
}

// OverrideRegistry allows setting a registry which will act as a shared registry between multiple Senders.
func (c *Config) OverrideRegistry(registry go_metrics.Registry) {
// WithRegistry allows setting a registry which will act as a shared registry between multiple Senders.
func (c *Config) WithRegistry(registry go_metrics.Registry) {
c.registry = registry
}

func (c *Config) WithInternalErrors() {
c.useInternalErrors = true
}

func (c *Config) client() *api.Client {
return api.NewClient(api.ClientConfig{
Email: c.email,
Expand All @@ -180,9 +176,7 @@ func (c *Config) startWithInternalErrors(client *api.Client, dev *api.Device) (*
return nil, nil, err
}

if c.useInternalErrors {
sender.useInternalErrors = true
}
sender.useInternalErrors = true

return sender, errChan, nil
}
Expand Down
5 changes: 3 additions & 2 deletions lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ func NewSenderWithDeviceName(name string, errors chan<- error, cfg *Config) (*Se
}

// NewSenderWithDeviceNameWithErrors creates a new flow Sender given a device name address and Config.
// The returned error channel is managed internally and will be closed after Sender.Stop() is called.
// If the timeout of Sender.Stop() is reached, it will return before the internal error channel is closed
// The channel is closed after Sender.Stop is called and all flow has been dispatched.
func NewSenderWithDeviceNameWithErrors(name string, cfg *Config) (*Sender, <-chan error, error) {
client := cfg.client()
d, err := lookupdev(client.GetDeviceByName(name))
Expand All @@ -93,6 +92,8 @@ func NewSenderWithNewDevice(dev *api.DeviceCreate, errors chan<- error, cfg *Con
return cfg.start(client, d, errors)
}

// NewSenderWithNewDeviceWithErrors creates a new device and returns a new flow Sender and an error channel which will
// report errors generated from the Sender. The channel is closed after Sender.Stop is called and all flow has been dispatched
func NewSenderWithNewDeviceWithErrors(dev *api.DeviceCreate, cfg *Config) (*Sender, <-chan error, error) {
client := cfg.client()
d, err := client.CreateDevice(dev)
Expand Down
10 changes: 4 additions & 6 deletions lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ func TestNewSenderWithDeviceNameWithErrors_NoErrs(t *testing.T) {

registry := metrics.NewRegistry()
metrics2.StartWithSetConf(registry, &l, metricsurl.String(), email, token, "chf")
config.OverrideRegistry(registry)
config.WithInternalErrors()
config.WithRegistry(registry)

s, errors, err := libkflow.NewSenderWithDeviceNameWithErrors(device.Name, config)
assert.NoError(t, err)
Expand Down Expand Up @@ -132,8 +131,7 @@ func TestNewSenderWithDeviceNameWithErrors_WithErrs(t *testing.T) {

registry := metrics.NewRegistry()
metrics2.StartWithSetConf(registry, &l, metricsurl.String(), email, token, "chf")
config.OverrideRegistry(registry)
config.WithInternalErrors()
config.WithRegistry(registry)

s, errors, err := libkflow.NewSenderWithDeviceNameWithErrors(device.Name, config)
assert.NoError(t, err)
Expand Down Expand Up @@ -185,7 +183,7 @@ func TestNewSenderWithDeviceName_WithErrs_NoPanic(t *testing.T) {

registry := metrics.NewRegistry()
metrics2.StartWithSetConf(registry, &l, metricsurl.String(), email, token, "chf")
config.OverrideRegistry(registry)
config.WithRegistry(registry)

errors := make(chan error)

Expand Down Expand Up @@ -243,7 +241,7 @@ func TestNewSenderWithDeviceNameLeaks(t *testing.T) {

registry := metrics.NewRegistry()
metrics2.StartWithSetConf(registry, &l, metricsurl.String(), email, token, "chf")
config.OverrideRegistry(registry)
config.WithRegistry(registry)

// kick off the tick go routines from the go metrics library
// these are only started once per process
Expand Down

0 comments on commit 541ff6b

Please sign in to comment.