Skip to content

Commit

Permalink
Fix golangci-lint errors. (#23)
Browse files Browse the repository at this point in the history
* Fix CI-errors.
* Use SHA-hashes for non-official actions.
* Update actions.
  • Loading branch information
kirkeby authored Jun 7, 2022
1 parent 5e60b89 commit 0a4c035
Show file tree
Hide file tree
Showing 32 changed files with 82 additions and 114 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ jobs:
steps:
-
name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
-
name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
- name: golangci-lint
# TODO: fix golangci-lint errors and warnings, and remove continue-on-error
continue-on-error: true
uses: golangci/golangci-lint-action@v2
# Note: this is @v3.2.0.
uses: golangci/golangci-lint-action@537aa1903e5d359d0b27dbc19ddd22c5087f3fbc
with:
version: v1.43
args: --timeout=5m
-
name: Tests
run: |
Expand All @@ -41,12 +41,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: 1.16.x

- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: goreleaser deprecation
run: curl -sfL https://git.io/goreleaser | VERSION=v1.2.5 sh -s -- check
Expand Down
2 changes: 0 additions & 2 deletions api/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (

var (
awsSession *session.Session
awsCreds *credentials.Credentials
)

func initAws(ctx context.Context) {
Expand Down Expand Up @@ -46,7 +45,6 @@ func initAws(ctx context.Context) {
log.Error(ctx, "AWS not initialized", "error", err.Error())
return
}
awsCreds = creds
cfg := aws.NewConfig().WithRegion(config.AWS.Region).WithCredentials(creds)
if config.AWS.S3Endpoint != "" {
cfg = cfg.WithEndpoint(config.AWS.S3Endpoint)
Expand Down
4 changes: 2 additions & 2 deletions api/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestBackupController_Status(t *testing.T) {
}
createList(t, t.Name(), elems)
createList(t, t.Name()+"-2", elems)
dir, err := ioutil.TempDir("", t.Name())
dir, _ := ioutil.TempDir("", t.Name())
fileName := filepath.Join(dir, t.Name()+".bin")
payload := client.MultiListBackup{
Destination: &client.BackupDestination{
Expand Down Expand Up @@ -107,7 +107,7 @@ func TestBackupController_Delete(t *testing.T) {
}
createList(t, t.Name(), elems)
createList(t, t.Name()+"-2", elems)
dir, err := ioutil.TempDir("", t.Name())
dir, _ := ioutil.TempDir("", t.Name())
fileName := filepath.Join(dir, t.Name()+".bin")
payload := client.MultiListBackup{
Destination: &client.BackupDestination{
Expand Down
31 changes: 14 additions & 17 deletions api/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,21 @@ func (c *HealthController) Health(ctx *app.HealthHealthContext) error {
func (c *HealthController) memoryReader() {
ctx := c.Context
ticker := time.Tick(time.Minute)
for {
select {
case <-ticker:
var mem runtime.MemStats
runtime.ReadMemStats(&mem)
j, err := json.MarshalIndent(mem, "", "\t")
if err != nil {
log.Error(ctx, "unable to marshal memstats", "error", err.Error())
}
var m map[string]interface{}
err = json.Unmarshal(j, &m)
if err != nil {
log.Error(ctx, "unable to unmarshal memstats", "error", err.Error())
}
c.memoryMuStats.Lock()
c.memoryStats = m
c.memoryMuStats.Unlock()
for range ticker {
var mem runtime.MemStats
runtime.ReadMemStats(&mem)
j, err := json.MarshalIndent(mem, "", "\t")
if err != nil {
log.Error(ctx, "unable to marshal memstats", "error", err.Error())
}
var m map[string]interface{}
err = json.Unmarshal(j, &m)
if err != nil {
log.Error(ctx, "unable to unmarshal memstats", "error", err.Error())
}
c.memoryMuStats.Lock()
c.memoryStats = m
c.memoryMuStats.Unlock()
}
}

Expand Down
6 changes: 2 additions & 4 deletions api/lists.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,8 @@ func (c *ListsController) GetPercentile(ctx *app.GetPercentileListsContext) erro
if !ok {
return ctx.NotFound(goa.ErrNotFound("not_found", "list_id", ctx.ListID))
}
percentile := float64(50.0)
if fromTop, err2 := strconv.ParseFloat(ctx.FromTop, 64); err2 == nil {
percentile = fromTop
} else {
percentile, err := strconv.ParseFloat(ctx.FromTop, 64)
if err != nil {
return ctx.BadRequest(goa.InvalidParamTypeError("from_top", ctx.FromTop, "number"))
}
if percentile < 0 {
Expand Down
8 changes: 3 additions & 5 deletions api/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ const (
// ContentTypeMsgpack specifies a messagepack encoding.
// Compact and fast.
contentMsgpack = "application/msgpack"

// ContentTypeJSON forces JSON as transport protocol.
contentJSON = "application/json"
)

var (
Expand All @@ -52,6 +49,7 @@ var (
tClientManage *client.Client
)

//nolint:staticcheck
func TestMain(m *testing.M) {
lr := logrus.New()
lr.Formatter = &logrus.TextFormatter{DisableColors: true}
Expand All @@ -65,7 +63,7 @@ func TestMain(m *testing.M) {
err = conf.Close()
exitOnFailure(err)
enableJWTCreation = true
go StartServices(logger, ctx, err)
go StartServices(logger, ctx)
<-listening

// Initialize clients
Expand Down Expand Up @@ -107,7 +105,7 @@ func initClient(ctx context.Context, dstClient **client.Client, scope string) {
"scopes": scope, // token scope - not a standard claim
}
token.Claims = claims
signedToken, err := token.SignedString(privKey)
signedToken, _ := token.SignedString(privKey)

cl.JWTSigner = &goaclient.JWTSigner{
TokenSource: &goaclient.StaticTokenSource{
Expand Down
2 changes: 1 addition & 1 deletion api/multilist.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ func onEveryList(ctx context.Context, lists rankdb.ListIDs, limit int, fn func(l
var mu sync.Mutex
var results = app.RankdbResultlist{
Success: make(map[string]*app.RankdbOperationSuccess, len(lists)),
Errors: make(map[string]string, 0),
Errors: make(map[string]string),
}
var tokens = make(chan struct{}, limit)
for i := 0; i < limit; i++ {
Expand Down
2 changes: 1 addition & 1 deletion api/multilist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ func TestMultilistController_Backup(t *testing.T) {
}
createList(t, t.Name(), elems)
createList(t, t.Name()+"-2", elems)
dir, err := ioutil.TempDir("", t.Name())
dir, _ := ioutil.TempDir("", t.Name())
fileName := filepath.Join(dir, t.Name()+".bin")
payload := client.MultiListBackup{
Destination: &client.BackupDestination{
Expand Down
26 changes: 13 additions & 13 deletions api/newrelic.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,16 @@ func NewRelicTx() goa.Middleware {
app := nrApp.app
txn := app.StartTransaction(goa.ContextController(ctx)+"."+goa.ContextAction(ctx), rw, req)
r := goa.ContextRequest(ctx)
txn.AddAttribute("source_ip", from(req))
_ = txn.AddAttribute("source_ip", from(req))

if config.Debug && len(r.Header) > 0 {
for k, v := range r.Header {
txn.AddAttribute("header_"+k, `"`+strings.Join(v, `","`)+`"`)
_ = txn.AddAttribute("header_"+k, `"`+strings.Join(v, `","`)+`"`)
}
}
if len(r.Params) > 0 {
for k, v := range r.Params {
txn.AddAttribute("param_"+k, `"`+strings.Join(v, `","`)+`"`)
_ = txn.AddAttribute("param_"+k, `"`+strings.Join(v, `","`)+`"`)
}
}
if config.Debug && r.ContentLength > 0 && r.ContentLength < 1024 {
Expand All @@ -113,10 +113,10 @@ func NewRelicTx() goa.Middleware {
if err != nil {
js = []byte("<invalid JSON>")
}
txn.AddAttribute("payload_json", string(js))
_ = txn.AddAttribute("payload_json", string(js))
}
ierr := func(msg string, keyvals ...interface{}) {
txn.NoticeError(errors.New(msg))
_ = txn.NoticeError(errors.New(msg))
for len(keyvals) > 0 {
key := fmt.Sprint(keyvals[0])
keyvals = keyvals[1:]
Expand All @@ -125,7 +125,7 @@ func NewRelicTx() goa.Middleware {
val = fmt.Sprint(keyvals[0])
keyvals = keyvals[1:]
}
txn.AddAttribute(key, val)
_ = txn.AddAttribute(key, val)
}
}
var ninfo int
Expand All @@ -136,7 +136,7 @@ func NewRelicTx() goa.Middleware {
ninfo++
mu.Unlock()
if n < 10 {
txn.AddAttribute(fmt.Sprintf("info_msg_%d", n), formatMsg(msg, keyvals, false))
_ = txn.AddAttribute(fmt.Sprintf("info_msg_%d", n), formatMsg(msg, keyvals, false))
}
}
intLogger := log.Intercept(log.Logger(ctx), iinfo, ierr)
Expand All @@ -146,18 +146,18 @@ func NewRelicTx() goa.Middleware {
defer func() {
resp := goa.ContextResponse(ctx)
if code := resp.ErrorCode; code != "" {
txn.AddAttribute("error_code", code)
txn.NoticeError(err)
_ = txn.AddAttribute("error_code", code)
_ = txn.NoticeError(err)
} else if resp.Status >= 500 || err != nil {
err2 := err
if err == nil {
err2 = errors.New(resp.ErrorCode)
}
txn.NoticeError(err2)
_ = txn.NoticeError(err2)
}
txn.AddAttribute("response_status_code", resp.Status)
txn.AddAttribute("response_bytes", resp.Length)
txn.End()
_ = txn.AddAttribute("response_status_code", resp.Status)
_ = txn.AddAttribute("response_bytes", resp.Length)
_ = txn.End()
}()
return err
}
Expand Down
1 change: 0 additions & 1 deletion api/rankdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ func StartServer(ctx context.Context, confData io.Reader, lr *logrus.Logger) err
updateBucket = rankdb.NewBucket(config.MaxUpdates)
}
if config.CacheEntries > 0 {
err = nil
switch config.CacheType {
case "", "ARC":
cache, err = lru.NewARC(config.CacheEntries)
Expand Down
2 changes: 1 addition & 1 deletion api/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var (
listenAddr net.Addr
)

func StartServices(logger goa.LogAdapter, ctx context.Context, err error) {
func StartServices(logger goa.LogAdapter, ctx context.Context) {
shutdown.PreShutdownFn(func() {
close(shutdownStarted)
})
Expand Down
3 changes: 1 addition & 2 deletions api/shutdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
var (
errShutdown = goa.NewErrorClass("server_restarting", http.StatusServiceUnavailable)("Server restarting")
errCancelled = goa.NewErrorClass("request_cancelled", 499)("Request Cancelled")
shutdownStarted = make(chan struct{}, 0)
shutdownStarted = make(chan struct{})
)

// ShutdownMiddleware rejects request once shutdown starts.
Expand All @@ -32,7 +32,6 @@ func ShutdownMiddleware(h goa.Handler) goa.Handler {
err := h(ctx, rw, req)
if err == context.Canceled || ctx.Err() == context.Canceled {
log.Info(ctx, "Context was cancelled")
err = nil
if shutdown.Started() {
return errShutdown
}
Expand Down
2 changes: 1 addition & 1 deletion api/tool/rankdb-cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func main() {

// Execute!
if err := app.Execute(); err != nil {
fmt.Fprintf(os.Stderr, err.Error())
fmt.Fprint(os.Stderr, err.Error())
os.Exit(-1)
}
}
Expand Down
1 change: 0 additions & 1 deletion backup/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ func (id ID) Cancel() {
return
}
job.cancel()
return
}

func (id ID) String() string {
Expand Down
2 changes: 1 addition & 1 deletion backup/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (f *File) Save(ctx context.Context) (io.WriteCloser, error) {
go func() {
res, err := uploader.UploadWithContext(ctx, &input)
if err != nil {
reader.CloseWithError(err)
_ = reader.CloseWithError(err)
log.Error(ctx, "Unable to upload data", "error", err.Error())
}
f.Result <- res
Expand Down
2 changes: 1 addition & 1 deletion backup/server/rankdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (b *bodyWriter) Transfer(ctx context.Context) {
}
log.Info(ctx, "Destination server returned ok", "full_path", b.req.URL.String())
b.r.Close()
io.Copy(ioutil.Discard, resp.Body)
_, _ = io.Copy(ioutil.Discard, resp.Body)
resp.Body.Close()
}

Expand Down
2 changes: 1 addition & 1 deletion blobstore/badgerstore/badger.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (b *BadgerStore) flush() error {
txn := b.db.NewTransaction(true)
for k, v := range b.queue {
if err := txn.Set([]byte(k), v); err == badger.ErrTxnTooBig {
err = txn.Commit()
_ = txn.Commit()
txn = b.db.NewTransaction(true)
err = txn.Set([]byte(k), v)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions blobstore/bstest/bstest.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//nolint
// Package bstest supplies helpers to test blobstores.
package bstest

Expand Down Expand Up @@ -255,6 +256,7 @@ func (t Test) Colliding(ctx context.Context, tt *testing.T) {
}
gRNG := rand.New(rand.NewSource(1337))
set, key := randStringRng(20, gRNG.Int63()), randStringRng(20, gRNG.Int63())
//nolint:errcheck
test := func(i int) {
rng := rand.New(rand.NewSource(int64(i)))
var blobSize = int(rng.Int63()%MaxBlobSize) + 1
Expand Down
3 changes: 2 additions & 1 deletion blobstore/lazysaver.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func NewLazySaver(store Store, opts ...lazySaveOption) (*LazySaver, error) {
cacheIdx: make(map[string]*list.Element),
itemAdded: make(chan struct{}, 1),
savech: make(chan *list.Element),
shutdownCh: make(chan struct{}, 0),
shutdownCh: make(chan struct{}),
}
for _, opt := range opts {
err := opt(&l.lazySaveOptions)
Expand Down Expand Up @@ -681,5 +681,6 @@ func putDataBufferChunk(p []byte) {
if size >= 1<<20 {
i = 10
}
//nolint - don't tell me what to make pointerlike
dataChunkPools[i].Put(p[:0])
}
4 changes: 2 additions & 2 deletions cmd/rankdb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func main() {
var dumpOnce sync.Once
shutdown.OnTimeout(func(stage shutdown.Stage, s string) {
dumpOnce.Do(func() {
pprof.Lookup("goroutine").WriteTo(lr.Out, 1)
_ = pprof.Lookup("goroutine").WriteTo(lr.Out, 1)
})
})

Expand All @@ -74,7 +74,7 @@ func main() {
}
}()
}
api.StartServices(logger, ctx, err)
api.StartServices(logger, ctx)
}

// exitOnFailure prints a fatal error message and exits the process with status 1.
Expand Down
Loading

0 comments on commit 0a4c035

Please sign in to comment.