Skip to content

Commit

Permalink
fix: lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
maier committed Jun 9, 2021
1 parent a5f12ed commit 36f7066
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ linters:
- goconst
# - stylecheck
- forcetypeassert
- goimports
# - goimports
disable:
- scopelint # deprecated
- golint # deprecated
Expand Down
4 changes: 2 additions & 2 deletions log.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package trapcheck

import "log"

// Logger is a generic logging interface
// Logger is a generic logging interface.
type Logger interface {
Printf(fmt string, v ...interface{})
Debugf(fmt string, v ...interface{})
Expand All @@ -16,7 +16,7 @@ type Logger interface {
Errorf(fmt string, v ...interface{})
}

// LogWrapper is a wrapper around Go's log.Logger
// LogWrapper is a wrapper around Go's log.Logger.
type LogWrapper struct {
Log *log.Logger
Debug bool
Expand Down
3 changes: 1 addition & 2 deletions submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (tc *TrapCheck) submit(ctx context.Context, metricBuffer *strings.Builder)
if cie.Reason == x509.NameMismatch {
tc.Log.Warnf("certificate name mismatch (refreshing TLS config) common cause, new broker added to cluster or check moved to new broker: %s", cie.Detail)
tc.clearTLSConfig()
return false, err
return false, fmt.Errorf("x509 cert name mismatch: %w", err)
}
} else {
tc.Log.Warnf("request error (%s): %s", resp.Request.URL, err)
Expand All @@ -203,7 +203,6 @@ func (tc *TrapCheck) submit(ctx context.Context, metricBuffer *strings.Builder)

reqStart = time.Now()
resp, err := retryClient.Do(req)
// TODO: catch invalid cert error and return refresh check=true
if resp != nil {
defer resp.Body.Close()
}
Expand Down
8 changes: 4 additions & 4 deletions tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (tc *TrapCheck) clearTLSConfig() {
}

// setBrokerTLSConfig sets the broker tls configuration if was
// not supplied by the caller in the configuration
// not supplied by the caller in the configuration.
func (tc *TrapCheck) setBrokerTLSConfig() error {

// setBrokerTLSConfig has already initialized it
Expand Down Expand Up @@ -98,7 +98,7 @@ func (tc *TrapCheck) setBrokerTLSConfig() error {
opts.Intermediates.AddCert(cert)
}
_, err := cs.PeerCertificates[0].Verify(opts)
return err
return fmt.Errorf("peer cert verify: %w", err)
},
}

Expand All @@ -107,12 +107,12 @@ func (tc *TrapCheck) setBrokerTLSConfig() error {
return nil
}

// caCert contains broker CA certificate returned from Circonus API
// caCert contains broker CA certificate returned from Circonus API.
type caCert struct {
Contents string `json:"contents"`
}

// fetchCert fetches CA certificate using Circonus API
// fetchCert fetches CA certificate using Circonus API.
func (tc *TrapCheck) fetchCert() ([]byte, error) {

tc.Log.Debugf("fetching broker cert from api")
Expand Down
10 changes: 5 additions & 5 deletions trapcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ type TrapCheck struct {

// New creates a new TrapCheck instance
// it will create a check if it is not able to find
// one based on the passed Check Config and Check Search Tag
// one based on the passed Check Config and Check Search Tag.
func New(cfg *Config) (*TrapCheck, error) {
if cfg == nil {
return nil, fmt.Errorf("invalid configuration (nil)")
Expand Down Expand Up @@ -139,7 +139,7 @@ func New(cfg *Config) (*TrapCheck, error) {

// SendMetrics submits the metrics to the broker
// metrics must be valid JSON encoded data for the broker httptrap check
// returns trap results in a structure or an error
// returns trap results in a structure or an error.
func (tc *TrapCheck) SendMetrics(ctx context.Context, metrics *strings.Builder) (*TrapResult, error) {
if ctx == nil {
ctx = context.Background()
Expand Down Expand Up @@ -168,7 +168,7 @@ func (tc *TrapCheck) SendMetrics(ctx context.Context, metrics *strings.Builder)

// GetCheckBundle returns the trap check bundle currently in use - can be used
// for caching checks on disk and re-using the ckeck quickly by passing
// the CID in via the check bundle config
// the CID in via the check bundle config.
func (tc *TrapCheck) GetCheckBundle() (*apiclient.CheckBundle, error) {
if tc.checkBundle == nil {
return nil, fmt.Errorf("trap check not initialized/created")
Expand All @@ -178,7 +178,7 @@ func (tc *TrapCheck) GetCheckBundle() (*apiclient.CheckBundle, error) {

// GetBrokerTLSConfig returns the current tls config - can be used
// for pre-seeding multiple check creation without repeatedly
// calling the API for the same CA cert - returns tls config, error
// calling the API for the same CA cert - returns tls config, error.
func (tc *TrapCheck) GetBrokerTLSConfig() (*tls.Config, error) {
if public, err := tc.isPublicBroker(); err != nil {
return nil, err
Expand Down Expand Up @@ -217,7 +217,7 @@ func (tc *TrapCheck) TraceMetrics(trace string) (string, error) {
return curr, nil
}

// testTraceMetricsDir verifies the trace metrics directory exists and is writeable
// testTraceMetricsDir verifies the trace metrics directory exists and is writeable.
func testTraceMetricsDir(dir string) error {
if dir == "" {
return fmt.Errorf("invalid trace setting (empty)")
Expand Down
4 changes: 2 additions & 2 deletions trapcheck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ func TestTrapCheck_GetBrokerTLSConfig(t *testing.T) {
},
{
name: "valid",
brokerTLS: &tls.Config{ServerName: "foobar"},
want: &tls.Config{ServerName: "foobar"},
brokerTLS: &tls.Config{ServerName: "foobar", MinVersion: tls.VersionTLS12},
want: &tls.Config{ServerName: "foobar", MinVersion: tls.VersionTLS12},
wantErr: false,
},
}
Expand Down

0 comments on commit 36f7066

Please sign in to comment.