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

update golangci-lint & goimports-reviser ; fix make format check errors #1343

Merged
merged 1 commit into from
Aug 26, 2022
Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 1 addition & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,8 @@ linters:
enable:
- revive
- goimports
- varcheck
- unused
- unparam
- deadcode
- structcheck
- errcheck
0pcom marked this conversation as resolved.
Show resolved Hide resolved
- gosimple
- staticcheck
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ format: tidy ## Formats the code. Must have goimports and goimports-reviser inst
${OPTS} goimports -w -local ${PROJECT_BASE} ./pkg
${OPTS} goimports -w -local ${PROJECT_BASE} ./cmd
${OPTS} goimports -w -local ${PROJECT_BASE} ./internal
find . -type f -name '*.go' -not -path "./.git/*" -not -path "./vendor/*" -exec goimports-reviser -project-name ${PROJECT_BASE} -file-path {} \;
find . -type f -name '*.go' -not -path "./.git/*" -not -path "./vendor/*" -exec goimports-reviser -project-name ${PROJECT_BASE} {} \;

format-windows: tidy ## Formats the code. Must have goimports and goimports-reviser installed (use make install-linters).
powershell 'Get-ChildItem -Directory | where Name -NotMatch vendor | % { Get-ChildItem $$_ -Recurse -Include *.go } | % {goimports -w -local ${PROJECT_BASE} $$_ }'
Expand Down
8 changes: 6 additions & 2 deletions cmd/apps/skychat/skychat.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,12 @@ func main() {
}()
}
setAppStatus(appCl, appserver.AppDetailedStatusRunning)

err := http.ListenAndServe(*addr, nil)
srv := &http.Server{
Addr: *addr,
ReadTimeout: 5 * time.Second,
WriteTimeout: 10 * time.Second,
}
err := srv.ListenAndServe()
if err != nil {
print(err.Error())
setAppError(appCl, err)
Expand Down
1 change: 1 addition & 0 deletions cmd/apps/vpn-client/vpn-client.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main vpn-client.go
package main

import (
Expand Down
1 change: 1 addition & 0 deletions cmd/apps/vpn-server/vpn-server.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main vpn-server.go
package main

import (
Expand Down
4 changes: 2 additions & 2 deletions cmd/setup-node/commands/root.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Package commands root.go
package commands

import (
"bufio"
"context"
"encoding/json"
"io"
"io/ioutil"
"os"

cc "github.com/ivanpirog/coloredcobra"
Expand Down Expand Up @@ -80,7 +80,7 @@ var rootCmd = &cobra.Command{

conf := &setup.Config{}

raw, err := ioutil.ReadAll(rdr)
raw, err := io.ReadAll(rdr)
if err != nil {
log.Fatalf("Failed to read config: %v", err)
}
Expand Down
1 change: 1 addition & 0 deletions cmd/setup-node/setup-node.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/*Package main setup-node*/
package main

import (
Expand Down
1 change: 1 addition & 0 deletions cmd/skywire-cli/commands/completion/completion.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package clicompletion generate completion script
package clicompletion

import (
Expand Down
1 change: 1 addition & 0 deletions cmd/skywire-cli/commands/config/gen.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package cliconfig gen.go
package cliconfig

import (
Expand Down
1 change: 1 addition & 0 deletions cmd/skywire-cli/commands/dmsgpty/hvdmsg.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package clidmsgpty hvdmsg.go
package clidmsgpty

import (
Expand Down
1 change: 1 addition & 0 deletions cmd/skywire-cli/commands/mdisc/root.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package climdisc root.go
package climdisc

import (
Expand Down
1 change: 1 addition & 0 deletions cmd/skywire-cli/commands/root.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package commands root.go
package commands

import (
Expand Down
1 change: 1 addition & 0 deletions cmd/skywire-cli/commands/rpc/root.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package clirpc root.go
package clirpc

import (
Expand Down
1 change: 1 addition & 0 deletions cmd/skywire-cli/commands/rtfind/root.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package clirtfind subcommand for skywire-cli
package clirtfind

import (
Expand Down
1 change: 1 addition & 0 deletions cmd/skywire-cli/commands/visor/app.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package clivisor app.go
package clivisor

import (
Expand Down
1 change: 1 addition & 0 deletions cmd/skywire-cli/commands/vpn/root.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package clivpn root.go
package clivpn

import (
Expand Down
2 changes: 2 additions & 0 deletions cmd/skywire-cli/commands/vpn/vvpn.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ func init() {
}
vpnUICmd.Flags().BoolVarP(&isPkg, "pkg", "p", false, "use package config path")
vpnUICmd.Flags().StringVarP(&path, "config", "c", "", "config path")
vpnURLCmd.Flags().BoolVarP(&isPkg, "pkg", "p", false, "use package config path")
vpnURLCmd.Flags().StringVarP(&path, "config", "c", "", "config path")
vpnListCmd.Flags().BoolVarP(&isUnFiltered, "nofilter", "n", false, "provide unfiltered results")
vpnListCmd.Flags().StringVarP(&ver, "ver", "v", version, "filter results by version")
vpnListCmd.Flags().StringVarP(&country, "country", "c", "", "filter results by country")
Expand Down
1 change: 1 addition & 0 deletions cmd/skywire-cli/internal/internal.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package internal contain functions used internally by different skywire-cli subcommands
package internal

import (
Expand Down
1 change: 1 addition & 0 deletions cmd/skywire-cli/skywire-cli.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main skywire-cli.go
package main

import (
Expand Down
1 change: 1 addition & 0 deletions cmd/skywire-visor/commands/nosystray.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//go:build !systray
// +build !systray

// Package commands nosystray.go
package commands

import (
Expand Down
11 changes: 8 additions & 3 deletions cmd/skywire-visor/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"fmt"
"io"
"io/fs"
"io/ioutil"
"net"
"net/http"
_ "net/http/pprof" // nolint:gosec // https://golang.org/doc/diagnostics.html#profiling
Expand Down Expand Up @@ -386,7 +385,7 @@ func initLogger(tag string, syslogAddr string) *logging.MasterLogger {
mLog.WithError(err).Error("Failed to connect to the syslog daemon.")
} else {
mLog.AddHook(hook)
mLog.Out = ioutil.Discard
mLog.Out = io.Discard
}
}
return mLog
Expand All @@ -399,7 +398,13 @@ func initPProf(log *logging.MasterLogger, tag string, profMode string, profAddr
case "none", "":
case "http":
go func() {
err := http.ListenAndServe(profAddr, nil)
srv := &http.Server{
Addr: profAddr,
Handler: nil,
ReadTimeout: 5 * time.Second,
WriteTimeout: 10 * time.Second,
}
err := srv.ListenAndServe()
log.WithError(err).
WithField("mode", profMode).
WithField("addr", profAddr).
Expand Down
16 changes: 8 additions & 8 deletions internal/httpauth/client.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package httpauth http authorizatioon
package httpauth

import (
Expand All @@ -7,7 +8,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"strconv"
Expand Down Expand Up @@ -99,14 +99,14 @@ func (c *Client) do(client *http.Client, req *http.Request) (*http.Response, err

body := make([]byte, 0)
if req.ContentLength != 0 {
auxBody, err := ioutil.ReadAll(req.Body)
auxBody, err := io.ReadAll(req.Body)
if err != nil {
return nil, err
}
if err := req.Body.Close(); err != nil {
c.log.WithError(err).Warn("Failed to close HTTP request body")
}
req.Body = ioutil.NopCloser(bytes.NewBuffer(auxBody))
req.Body = io.NopCloser(bytes.NewBuffer(auxBody))
body = auxBody
}

Expand All @@ -131,7 +131,7 @@ func (c *Client) do(client *http.Client, req *http.Request) (*http.Response, err
c.log.WithError(err).Warn("Failed to close HTTP response body")
}

req.Body = ioutil.NopCloser(bytes.NewBuffer(body))
req.Body = io.NopCloser(bytes.NewBuffer(body))

resp, err = c.doRequest(client, req, body)
if err != nil {
Expand Down Expand Up @@ -227,15 +227,15 @@ func isNonceValid(res *http.Response) (*http.Response, bool, error) {
var serverResponse HTTPResponse
var auxResp http.Response

auxRespBody, err := ioutil.ReadAll(res.Body)
auxRespBody, err := io.ReadAll(res.Body)
if err != nil {
return nil, false, err
}
if err := res.Body.Close(); err != nil {
return nil, false, err
}
auxResp = *res
auxResp.Body = ioutil.NopCloser(bytes.NewBuffer(auxRespBody))
auxResp.Body = io.NopCloser(bytes.NewBuffer(auxRespBody))

if err := json.Unmarshal(auxRespBody, &serverResponse); err != nil || serverResponse.Error == nil {
return &auxResp, true, nil
Expand Down Expand Up @@ -269,7 +269,7 @@ func sanitizedAddr(addr string) string {
func extractHTTPError(r io.Reader) error {
var serverError HTTPResponse

body, err := ioutil.ReadAll(r)
body, err := io.ReadAll(r)
if err != nil {
return err
}
Expand All @@ -285,7 +285,7 @@ func extractHTTPError(r io.Reader) error {
func ExtractError(r io.Reader) error {
var apiError Error

body, err := ioutil.ReadAll(r)
body, err := io.ReadAll(r)
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions internal/httpauth/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"os"
Expand Down Expand Up @@ -58,7 +58,7 @@ func TestClient(t *testing.T) {
res, err := c.Do(req)
require.NoError(t, err)

b, err := ioutil.ReadAll(res.Body)
b, err := io.ReadAll(res.Body)
require.NoError(t, err)
require.NoError(t, res.Body.Close())
assert.Equal(t, []byte(payload), b)
Expand Down Expand Up @@ -86,7 +86,7 @@ func TestClient_BadNonce(t *testing.T) {
res, err := c.Do(req)
require.NoError(t, err)

b, err := ioutil.ReadAll(res.Body)
b, err := io.ReadAll(res.Body)
require.NoError(t, err)
require.NoError(t, res.Body.Close())
assert.Equal(t, uint64(2), c.nonce)
Expand All @@ -109,7 +109,7 @@ func newTestServer(t *testing.T, pk cipher.PubKey, headerCh chan<- http.Header)
if r.URL.String() == fmt.Sprintf("/security/nonces/%s", pk) {
require.NoError(t, json.NewEncoder(w).Encode(&NextNonceResponse{pk, Nonce(nonce)}))
} else {
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if body != nil {
defer func() {
require.NoError(t, r.Body.Close())
Expand Down
1 change: 1 addition & 0 deletions internal/packetfilter/address-filter.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/*Package packetfilter filter packets*/
package packetfilter

import (
Expand Down
1 change: 1 addition & 0 deletions internal/skysocks/client.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package skysocks client.go
package skysocks

import (
Expand Down
4 changes: 2 additions & 2 deletions internal/skysocks/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package skysocks

import (
"fmt"
"io/ioutil"
"io"
"net"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -79,7 +79,7 @@ func TestProxy(t *testing.T) {
res, err := c.Get(ts.URL)
require.NoError(t, err)

msg, err := ioutil.ReadAll(res.Body)
msg, err := io.ReadAll(res.Body)
require.NoError(t, err)
require.NoError(t, res.Body.Close())
assert.Equal(t, "Hello, client\n", string(msg))
Expand Down
1 change: 1 addition & 0 deletions internal/vpn/client.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package vpn internal vpn
package vpn

import (
Expand Down
3 changes: 1 addition & 2 deletions pkg/app/appcommon/log_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package appcommon

import (
"fmt"
"io/ioutil"
"os"
"testing"
"time"
Expand All @@ -11,7 +10,7 @@ import (
)

func TestLogStore(t *testing.T) {
p, err := ioutil.TempFile("", "test-db")
p, err := os.CreateTemp("", "test-db")
require.NoError(t, err)

defer os.Remove(p.Name()) // nolint
Expand Down
1 change: 1 addition & 0 deletions pkg/app/appdisc/discovery_manager.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package appdisc updates app discovery
package appdisc

import (
Expand Down
1 change: 1 addition & 0 deletions pkg/app/appevent/broadcaster.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package appevent broadcaster.go
package appevent

import (
Expand Down
1 change: 1 addition & 0 deletions pkg/app/idmanager/delta_informer.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package idmanager delta_informer.go
package idmanager

// DeltaInformer informs when there has been a change to the id-manager.
Expand Down
1 change: 1 addition & 0 deletions pkg/app/launcher/launcher.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package launcher launcher.go
package launcher

import (
Expand Down
1 change: 1 addition & 0 deletions pkg/dmsgc/dmsgc.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package dmsgc dmsg config and client
package dmsgc

import (
Expand Down
1 change: 1 addition & 0 deletions pkg/restart/restart.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package restart restart.go
package restart

import (
Expand Down
1 change: 1 addition & 0 deletions pkg/router/routerclient/client.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package routerclient client.go
package routerclient

import (
Expand Down
5 changes: 3 additions & 2 deletions pkg/routing/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import (
// Packet defines generic packet recognized by all skywire visors.
// The unit of communication for routing/router is called packets.
// Packet format:
// | type (byte) | route ID (uint32) | payload size (uint16) | payload (~) |
// | 1[0:1] | 4[1:5] | 2[5:7] | [7:~] |
//
// | type (byte) | route ID (uint32) | payload size (uint16) | payload (~) |
// | 1[0:1] | 4[1:5] | 2[5:7] | [7:~] |
type Packet []byte

// Packet sizes and offsets.
Expand Down
1 change: 0 additions & 1 deletion pkg/routing/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ const (

// Rule represents a routing rule.
// There are two types of routing rules; App and Forward.
//
type Rule []byte

func (r Rule) assertLen(l int) {
Expand Down
1 change: 1 addition & 0 deletions pkg/servicedisc/autoconnect.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package servicedisc works with the service discovery
package servicedisc

import (
Expand Down
Loading