Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: enable a bunch of new linting rules at once #179

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,25 @@ linters:
disable-all: true
enable:
- errcheck
- gci
# - goconst
- gocritic
- gocyclo
- gofmt
- goimports
- gosimple
- govet
- gofmt
- gci
- revive
- ineffassign
- megacheck
- misspell
- revive
- staticcheck
- typecheck
- unconvert
issues:
exclude-rules:
- path: example.*_test\.go
linters:
- ineffassign
- revive
exclude-use-default: false
2 changes: 1 addition & 1 deletion application/heartbeater.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (hb *heartbeater) beat() {
hb.send(tags)
}

//send customTags heartbeat
// send customTags heartbeat
hb.mux.Lock()
for len(hb.customTags) > 0 {
tags := hb.customTags[0]
Expand Down
8 changes: 4 additions & 4 deletions internal/sdkmetrics/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ func (f *fakeSender) SendDeltaCounter(string, float64, string, map[string]string
func (f *fakeSender) SendMetric(name string, _ float64, _ int64, _ string, tags map[string]string) error {
f.count = f.count + 1
if f.prefix != "" && !strings.HasPrefix(name, f.prefix) {
f.errors = f.errors + 1
f.errors++
}
if f.name != "" && f.prefix != "" && (name != f.prefix+"."+f.name) {
f.errors = f.errors + 1
f.errors++
}
for _, k := range f.tags {
if tags == nil {
f.errors = f.errors + 1
f.errors++
} else {
if _, ok := tags[k]; !ok {
f.errors = f.errors + 1
f.errors++
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions internal/span/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/wavefronthq/wavefront-sdk-go/internal"
)

// Line gets a span line in the Wavefront span data format:
// Line returns a span line in the Wavefront span data format:
// <tracingSpanName> source=<source> [pointTags] <start_millis> <duration_milli_seconds>
// Example:
// "getAllUsers source=localhost traceId=7b3bf470-9456-11e8-9eb6-529269fb1459 spanId=0313bafe-9457-11e8-9eb6-529269fb1459
Expand Down Expand Up @@ -80,6 +80,7 @@ func Line(name string, startMillis, durationMillis int64, source, traceID, spanI
return sb.String(), nil
}

// LogJSON returns Span Logs as a string in JSON format,
func LogJSON(traceID, spanID string, spanLogs []Log, span string) (string, error) {
l := Logs{
TraceID: traceID,
Expand All @@ -91,7 +92,7 @@ func LogJSON(traceID, spanID string, spanLogs []Log, span string) (string, error
if err != nil {
return "", err
}
return string(out[:]) + "\n", nil
return string(out) + "\n", nil
}

func isUUIDFormat(str string) bool {
Expand Down
11 changes: 4 additions & 7 deletions senders/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,16 @@ import (
)

func tokenServiceForCfg(cfg *configuration) auth.Service {
switch cfg.Authentication.(type) {
switch a := cfg.Authentication.(type) {
case auth.APIToken:
log.Println("The Wavefront SDK will use Direct Ingestion authenticated using an API Token.")
tokenAuth := cfg.Authentication.(auth.APIToken)
return auth.NewWavefrontTokenService(tokenAuth.Token)
return auth.NewWavefrontTokenService(a.Token)
case auth.CSPClientCredentials:
log.Println("The Wavefront SDK will use Direct Ingestion authenticated using CSP client credentials.")
cspAuth := cfg.Authentication.(auth.CSPClientCredentials)
return auth.NewCSPServerToServerService(cspAuth.BaseURL, cspAuth.ClientID, cspAuth.ClientSecret, cspAuth.OrgID)
return auth.NewCSPServerToServerService(a.BaseURL, a.ClientID, a.ClientSecret, a.OrgID)
case auth.CSPAPIToken:
log.Println("The Wavefront SDK will use Direct Ingestion authenticated using CSP API Token.")
cspAuth := cfg.Authentication.(auth.CSPAPIToken)
return auth.NewCSPTokenService(cspAuth.BaseURL, cspAuth.Token)
return auth.NewCSPTokenService(a.BaseURL, a.Token)
}

log.Println("The Wavefront SDK will communicate with a Wavefront Proxy.")
Expand Down
3 changes: 1 addition & 2 deletions senders/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ func CSPBaseURL(baseURL string) CSPOption {
// CSPOrgID sets an explicit orgID for Client Credentials authentication
func CSPOrgID(orgID string) CSPOption {
return func(authentication any) {
switch a := authentication.(type) {
case auth.CSPClientCredentials:
if a, ok := authentication.(auth.CSPClientCredentials); ok {
a.OrgID = &orgID
}
}
Expand Down
40 changes: 18 additions & 22 deletions senders/real_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"strconv"
"strings"

"github.com/wavefronthq/wavefront-sdk-go/event"
"github.com/wavefronthq/wavefront-sdk-go/histogram"
Expand Down Expand Up @@ -197,29 +198,24 @@ func (sender *realSender) Close() {
}

func (sender *realSender) Flush() error {
errStr := ""
err := sender.pointHandler.Flush()
if err != nil {
errStr = errStr + err.Error() + "\n"
}
err = sender.histoHandler.Flush()
if err != nil {
errStr = errStr + err.Error() + "\n"
}
err = sender.spanHandler.Flush()
if err != nil {
errStr = errStr + err.Error()
}
err = sender.spanLogHandler.Flush()
if err != nil {
errStr = errStr + err.Error()
}
err = sender.eventHandler.Flush()
if err != nil {
errStr = errStr + err.Error()
return combineErrorMessages(
sender.pointHandler.Flush(),
sender.histoHandler.Flush(),
sender.spanHandler.Flush(),
sender.spanLogHandler.Flush(),
sender.eventHandler.Flush(),
)
}

func combineErrorMessages(errs ...error) error {
var nonNilErrMessages []string
for _, err := range errs {
if err != nil {
nonNilErrMessages = append(nonNilErrMessages, err.Error())
}
}
if errStr != "" {
return fmt.Errorf(errStr)
if len(nonNilErrMessages) > 0 {
return fmt.Errorf(strings.Join(nonNilErrMessages, "\n"))
}
return nil
}
Expand Down
Loading