Skip to content

Commit

Permalink
enable errorlint
Browse files Browse the repository at this point in the history
  • Loading branch information
lovromazgon committed Sep 11, 2024
1 parent e614879 commit 46b3b41
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ linters:
- errcheck
- errchkjson
- errname
# - errorlint # TODO enable
- errorlint
- exhaustive
# - forbidigo
# - forcetypeassert # TODO enable
Expand Down
30 changes: 15 additions & 15 deletions common/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,40 @@ import (
"github.com/nats-io/nats.go"
)

// GetConnectionOptions returns connection options based on the provided config.
func GetConnectionOptions(config Config) ([]nats.Option, error) {
// ConnectionOptions returns connection options based on the provided config.
func (c Config) ConnectionOptions() ([]nats.Option, error) {
var opts []nats.Option

if config.ConnectionName != "" {
opts = append(opts, nats.Name(config.ConnectionName))
if c.ConnectionName != "" {
opts = append(opts, nats.Name(c.ConnectionName))
}

if config.NKeyPath != "" {
opt, err := nats.NkeyOptionFromSeed(config.NKeyPath)
if c.NKeyPath != "" {
opt, err := nats.NkeyOptionFromSeed(c.NKeyPath)
if err != nil {
return nil, fmt.Errorf("load NKey pair: %w", err)
}

opts = append(opts, opt)
}

if config.CredentialsFilePath != "" {
opts = append(opts, nats.UserCredentials(config.CredentialsFilePath))
if c.CredentialsFilePath != "" {
opts = append(opts, nats.UserCredentials(c.CredentialsFilePath))
}

if config.TLS.ClientCertPath != "" && config.TLS.ClientPrivateKeyPath != "" {
if c.TLS.ClientCertPath != "" && c.TLS.ClientPrivateKeyPath != "" {
opts = append(opts, nats.ClientCert(
config.TLS.ClientCertPath,
config.TLS.ClientPrivateKeyPath,
c.TLS.ClientCertPath,
c.TLS.ClientPrivateKeyPath,
))
}

if config.TLS.RootCACertPath != "" {
opts = append(opts, nats.RootCAs(config.TLS.RootCACertPath))
if c.TLS.RootCACertPath != "" {
opts = append(opts, nats.RootCAs(c.TLS.RootCACertPath))
}

opts = append(opts, nats.MaxReconnects(config.MaxReconnects))
opts = append(opts, nats.ReconnectWait(config.ReconnectWait))
opts = append(opts, nats.MaxReconnects(c.MaxReconnects))
opts = append(opts, nats.ReconnectWait(c.ReconnectWait))

return opts, nil
}
5 changes: 2 additions & 3 deletions destination/destination.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"fmt"
"strings"

"github.com/conduitio-labs/conduit-connector-nats-pubsub/common"
"github.com/conduitio-labs/conduit-connector-nats-pubsub/destination/pubsub"
"github.com/conduitio/conduit-commons/config"
"github.com/conduitio/conduit-commons/opencdc"
Expand Down Expand Up @@ -66,9 +65,9 @@ func (d *Destination) Configure(ctx context.Context, cfg config.Config) error {

// Open makes sure everything is prepared to receive records.
func (d *Destination) Open(context.Context) error {
opts, err := common.GetConnectionOptions(d.config.Config)
opts, err := d.config.ConnectionOptions()
if err != nil {
return fmt.Errorf("get connection options: %s", err)
return fmt.Errorf("get connection options: %w", err)
}

conn, err := nats.Connect(strings.Join(d.config.URLs, ","), opts...)
Expand Down
3 changes: 1 addition & 2 deletions source/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"fmt"
"strings"

"github.com/conduitio-labs/conduit-connector-nats-pubsub/common"
"github.com/conduitio-labs/conduit-connector-nats-pubsub/source/pubsub"
"github.com/conduitio/conduit-commons/config"
"github.com/conduitio/conduit-commons/opencdc"
Expand Down Expand Up @@ -70,7 +69,7 @@ func (s *Source) Configure(ctx context.Context, cfg config.Config) error {
func (s *Source) Open(context.Context, opencdc.Position) error {
s.errC = make(chan error, 1)

opts, err := common.GetConnectionOptions(s.config.Config)
opts, err := s.config.ConnectionOptions()
if err != nil {
return fmt.Errorf("get connection options: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion test/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var (
func GetTestConnection(url string) (*nats.Conn, error) {
conn, err := nats.Connect(url)
if err != nil {
return nil, fmt.Errorf("connect to NATS server: %s", err)
return nil, fmt.Errorf("connect to NATS server: %w", err)
}

return conn, nil
Expand Down

0 comments on commit 46b3b41

Please sign in to comment.