Skip to content

Commit

Permalink
Fixing all the lint errors!
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaokangwang committed Jan 21, 2025
1 parent efec9ea commit bff47c8
Show file tree
Hide file tree
Showing 30 changed files with 63 additions and 58 deletions.
2 changes: 1 addition & 1 deletion app/commander/commander.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package commander

import (
"context"
"github.com/v2fly/v2ray-core/v5/features"
"net"
"sync"

Expand All @@ -14,6 +13,7 @@ import (
"github.com/v2fly/v2ray-core/v5/common"
"github.com/v2fly/v2ray-core/v5/common/serial"
"github.com/v2fly/v2ray-core/v5/common/signal/done"
"github.com/v2fly/v2ray-core/v5/features"
"github.com/v2fly/v2ray-core/v5/features/outbound"
"github.com/v2fly/v2ray-core/v5/infra/conf/v5cfg"
)
Expand Down
9 changes: 3 additions & 6 deletions app/commander/webcommander/webcommander.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func newWebCommander(ctx context.Context, config *Config) (*WebCommander, error)
}

return &WebCommander{ctx: ctx, config: config, webRootfs: webRootfs}, nil

}

type WebCommander struct {
Expand All @@ -56,9 +55,9 @@ type WebCommander struct {
}

func (w *WebCommander) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
api_path := w.config.ApiMountpoint
if strings.HasPrefix(request.URL.Path, api_path) {
request.URL.Path = strings.TrimPrefix(request.URL.Path, api_path)
apiPath := w.config.ApiMountpoint
if strings.HasPrefix(request.URL.Path, apiPath) {
request.URL.Path = strings.TrimPrefix(request.URL.Path, apiPath)
if w.wrappedGrpc.IsGrpcWebRequest(request) {
w.wrappedGrpc.ServeHTTP(writer, request)
return
Expand Down Expand Up @@ -109,7 +108,6 @@ func (w *WebCommander) Type() interface{} {
}

func (w *WebCommander) Start() error {

if err := core.RequireFeatures(w.ctx, func(cm commander.CommanderIfce, om outbound.Manager) {
w.Lock()
defer w.Unlock()
Expand All @@ -118,7 +116,6 @@ func (w *WebCommander) Start() error {
w.ohm = om

go w.asyncStart()

}); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion app/dns/dnscommon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func Test_parseResponse(t *testing.T) {
got.Expire = time.Time{}
}
if cmp.Diff(got, tt.want) != "" {
t.Errorf(cmp.Diff(got, tt.want))
t.Errorf("%v", cmp.Diff(got, tt.want))
// t.Errorf("handleResponse() = %#v, want %#v", got, tt.want)
}
})
Expand Down
1 change: 0 additions & 1 deletion app/router/command/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ func TestServiceSubscribeRoutingStats(t *testing.T) {
grpc.WithContextDialer(bufDialer),
grpc.WithTransportCredentials(insecure.NewCredentials()),
)

if err != nil {
errCh <- err
return
Expand Down
5 changes: 3 additions & 2 deletions app/subscription/containers/urlline/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package urlline
import (
"bufio"
"bytes"
"github.com/v2fly/v2ray-core/v5/app/subscription/containers"
"github.com/v2fly/v2ray-core/v5/common"
"net/url"
"strings"

"github.com/v2fly/v2ray-core/v5/app/subscription/containers"
"github.com/v2fly/v2ray-core/v5/common"
)

func newURLLineParser() containers.SubscriptionContainerDocumentParser {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ type materializedServer struct {
serverConfig *specs.SubscriptionServerConfig
}

func (s *trackedSubscription) fillStatus(status *subscription.TrackedSubscriptionStatus) error {
func (s *trackedSubscription) fillStatus(status *subscription.TrackedSubscriptionStatus) error { //nolint: unparam
status.ImportSource = s.importSource
if s.currentDocument == nil {
return nil
Expand Down
2 changes: 1 addition & 1 deletion common/net/packetaddr/packetaddr.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package packetaddr

import (
"bytes"
"github.com/v2fly/v2ray-core/v5/common/errors"
gonet "net"

"github.com/v2fly/v2ray-core/v5/common/buf"
"github.com/v2fly/v2ray-core/v5/common/errors"
"github.com/v2fly/v2ray-core/v5/common/net"
"github.com/v2fly/v2ray-core/v5/common/protocol"
)
Expand Down
2 changes: 1 addition & 1 deletion common/platform/platform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestWrongErrorCheckOnOSStat(t *testing.T) {
// be discovered by the Go runtime, which will lead to failure to
// find & read geoip & geosite files.
// The correct code is `errors.Is(err, fs.ErrNotExist)`
if _, err := os.Stat(p); err != nil && errors.Is(fs.ErrNotExist, err) {
if _, err := os.Stat(p); err != nil && errors.Is(err, fs.ErrNotExist) {
continue
}
// asset found
Expand Down
7 changes: 4 additions & 3 deletions infra/conf/v4/transport_internet.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,19 +147,20 @@ type Hy2ConfigCongestion struct {
type Hy2Config struct {
Password string `json:"password"`
Congestion Hy2ConfigCongestion `json:"congestion"`
UseUdpExtension bool `json:"use_udp_extension"`
UseUDPExtension bool `json:"use_udp_extension"`
IgnoreClientBandwidth bool `json:"ignore_client_bandwidth"`
}

// Build implements Buildable.
func (c *Hy2Config) Build() (proto.Message, error) {
return &hysteria2.Config{Password: c.Password,
return &hysteria2.Config{
Password: c.Password,
Congestion: &hysteria2.Congestion{
Type: c.Congestion.Type,
DownMbps: c.Congestion.DownMbps,
UpMbps: c.Congestion.UpMbps,
},
UseUdpExtension: c.UseUdpExtension,
UseUdpExtension: c.UseUDPExtension,
IgnoreClientBandwidth: c.IgnoreClientBandwidth,
}, nil
}
Expand Down
4 changes: 2 additions & 2 deletions infra/vprotogen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Command "%s" not found.
Make sure that %s is in your system path or current path.
Download %s v%s or later from https://github.com/protocolbuffers/protobuf/releases
`, protoc, protoc, protoc, targetedVersion)
return "", fmt.Errorf(errStr)
return "", fmt.Errorf("%v", errStr)
}
return path, nil
}
Expand Down Expand Up @@ -124,7 +124,7 @@ func getInstalledProtocVersion(protocPath string) (string, error) {
matched := versionRegexp.FindStringSubmatch(string(output))
installedVersion := ""
if len(matched) == 0 {
return "", errors.New("Can not parse protoc version.")
return "", errors.New("can not parse protoc version")
}

if len(matched) == 2 {
Expand Down
10 changes: 5 additions & 5 deletions main/commands/all/jsonv4/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func executeConvert(cmd *base.Command, args []string) {
r := bytes.NewReader(data)
pbConfig, err := core.LoadConfig(inputFormat, r)
if err != nil {
base.Fatalf(err.Error())
base.Fatalf("%v", err.Error())
}
out, err = proto.Marshal(pbConfig)
if err != nil {
Expand All @@ -133,12 +133,12 @@ func executeConvert(cmd *base.Command, args []string) {
r := bytes.NewReader(data)
pbConfig, err := core.LoadConfig(inputFormat, r)
if err != nil {
base.Fatalf(err.Error())
base.Fatalf("%v", err.Error())
}
w := bytes.NewBuffer(nil)
err = jsonpb.DumpJSONPb(pbConfig, w)
if err != nil {
base.Fatalf(err.Error())
base.Fatalf("%v", err.Error())
}
out = w.Bytes()
case v2jsonpb.FormatProtobufV2JSONPB:
Expand All @@ -149,11 +149,11 @@ func executeConvert(cmd *base.Command, args []string) {
r := bytes.NewReader(data)
pbConfig, err := core.LoadConfig(inputFormat, r)
if err != nil {
base.Fatalf(err.Error())
base.Fatalf("%v", err.Error())
}
out, err = v2jsonpb.DumpV2JsonPb(pbConfig)
if err != nil {
base.Fatalf(err.Error())
base.Fatalf("%v", err.Error())
}
default:
base.Errorf("invalid output format: %s", outputFormat)
Expand Down
2 changes: 1 addition & 1 deletion main/commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func readConfDirRecursively(dirPath string, extension []string) cmdarg.Arg {
func getConfigFilePath() cmdarg.Arg {
extension, err := core.GetLoaderExtensions(*configFormat)
if err != nil {
base.Fatalf(err.Error())
base.Fatalf("%v", err.Error())
}
dirReader := readConfDir
if *configDirRecursively {
Expand Down
4 changes: 2 additions & 2 deletions main/plugins/plugin_pprof/plugin_pprof.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package plugin_pprof
package plugin_pprof //nolint: stylecheck

import (
"github.com/v2fly/v2ray-core/v5/main/plugins"
"net/http"
"net/http/pprof"

"github.com/v2fly/v2ray-core/v5/main/commands/base"
"github.com/v2fly/v2ray-core/v5/main/plugins"
)

var pprofPlugin plugins.Plugin = func(cmd *base.Command) func() error {
Expand Down
2 changes: 1 addition & 1 deletion proxy/hysteria2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter

if !IsHy2Transport && network == net.Network_UDP {
// hysteria2 need to use udp extension to proxy UDP.
return newError(hyTransport.CanNotUseUdpExtension)
return newError(hyTransport.CanNotUseUDPExtension)
}

user := server.PickUser()
Expand Down
4 changes: 2 additions & 2 deletions proxy/hysteria2/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"io"
"math/rand"

hyProtocol "github.com/v2fly/hysteria/core/v2/international/protocol"
"github.com/apernet/quic-go/quicvarint"
hyProtocol "github.com/v2fly/hysteria/core/v2/international/protocol"

"github.com/v2fly/v2ray-core/v5/common/buf"
"github.com/v2fly/v2ray-core/v5/common/net"
Expand Down Expand Up @@ -59,7 +59,7 @@ func (c *ConnWriter) WriteTCPHeader() error {
}

func QuicLen(s int) int {
return int(quicvarint.Len(uint64(s)))
return quicvarint.Len(uint64(s))
}

func (c *ConnWriter) writeTCPHeader() error {
Expand Down
2 changes: 1 addition & 1 deletion proxy/hysteria2/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (s *Server) Process(ctx context.Context, network net.Network, conn internet
}

if !IsHy2Transport && network == net.Network_UDP {
return newError(hyTransport.CanNotUseUdpExtension)
return newError(hyTransport.CanNotUseUDPExtension)
}

sessionPolicy := s.policyManager.ForLevel(0)
Expand Down
2 changes: 1 addition & 1 deletion proxy/vlite/inbound/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func createStatusFromConfig(config *UDPProtocolConfig) (*status, error) { //noli
return s, nil
}

func enableInterface(s *status) error {
func enableInterface(s *status) error { //nolint: unparam
s.transport = s
if s.config.EnableStabilization {
s.transport = uniserver.NewUnifiedConnectionTransportHub(s, s.ctx)
Expand Down
5 changes: 3 additions & 2 deletions testing/scenarios/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"crypto/rand"
"fmt"
"golang.org/x/net/proxy"
"io"
"os"
"os/exec"
Expand All @@ -14,6 +13,8 @@ import (
"syscall"
"time"

"golang.org/x/net/proxy"

"google.golang.org/protobuf/proto"

core "github.com/v2fly/v2ray-core/v5"
Expand Down Expand Up @@ -169,7 +170,7 @@ func withDefaultApps(config *core.Config) *core.Config {
return config
}

func testTCPConnViaSocks(socksPort, testPort net.Port, payloadSize int, timeout time.Duration) func() error {
func testTCPConnViaSocks(socksPort, testPort net.Port, payloadSize int, timeout time.Duration) func() error { //nolint: unparam
return func() error {
socksDialer, err := proxy.SOCKS5("tcp", "127.0.0.1:"+socksPort.String(), nil, nil)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions transport/internet/httpupgrade/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package httpupgrade

import (
"context"
"io"
"time"

"github.com/v2fly/v2ray-core/v5/common/buf"
"github.com/v2fly/v2ray-core/v5/common/net"
"github.com/v2fly/v2ray-core/v5/common/serial"
"io"
"time"
)

type connection struct {
Expand Down
3 changes: 1 addition & 2 deletions transport/internet/httpupgrade/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func dialhttpUpgrade(ctx context.Context, dest net.Destination, streamSettings *
earlyDataSize = int(transportConfiguration.MaxEarlyData)
}

if earlyData != nil && len(earlyData) > 0 {
if len(earlyData) > 0 {
if transportConfiguration.EarlyDataHeaderName == "" {
return nil, nil, newError("EarlyDataHeaderName is not set")
}
Expand Down Expand Up @@ -71,7 +71,6 @@ func dialhttpUpgrade(ctx context.Context, dest net.Destination, streamSettings *
if resp.Status == "101 Switching Protocols" &&
strings.ToLower(resp.Header.Get("Upgrade")) == "websocket" &&
strings.ToLower(resp.Header.Get("Connection")) == "upgrade" {

earlyReplyReader := io.LimitReader(bufferedConn, int64(bufferedConn.Buffered()))
return conn, earlyReplyReader, nil
}
Expand Down
14 changes: 8 additions & 6 deletions transport/internet/hysteria2/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ package hysteria2
import (
"time"

"github.com/apernet/quic-go"
hyClient "github.com/v2fly/hysteria/core/v2/client"
"github.com/v2fly/hysteria/core/v2/international/protocol"
hyServer "github.com/v2fly/hysteria/core/v2/server"
"github.com/apernet/quic-go"

"github.com/v2fly/v2ray-core/v5/common/net"
)

const CanNotUseUdpExtension = "Only hysteria2 proxy protocol can use udpExtension."
const Hy2MustNeedTLS = "Hysteria2 based on QUIC that requires TLS."
const (
CanNotUseUDPExtension = "Only hysteria2 proxy protocol can use udpExtension."
Hy2MustNeedTLS = "Hysteria2 based on QUIC that requires TLS."
)

type HyConn struct {
IsUDPExtension bool
Expand Down Expand Up @@ -44,7 +46,7 @@ func (c *HyConn) Write(b []byte) (int, error) {

func (c *HyConn) WritePacket(b []byte, dest net.Destination) (int, error) {
if !c.IsUDPExtension {
return 0, newError(CanNotUseUdpExtension)
return 0, newError(CanNotUseUDPExtension)
}

if c.IsServer {
Expand All @@ -64,7 +66,7 @@ func (c *HyConn) WritePacket(b []byte, dest net.Destination) (int, error) {

func (c *HyConn) ReadPacket() (int, []byte, *net.Destination, error) {
if !c.IsUDPExtension {
return 0, nil, nil, newError(CanNotUseUdpExtension)
return 0, nil, nil, newError(CanNotUseUDPExtension)
}

if c.IsServer {
Expand All @@ -89,7 +91,7 @@ func (c *HyConn) ReadPacket() (int, []byte, *net.Destination, error) {
func (c *HyConn) Close() error {
if c.IsUDPExtension {
if !c.IsServer && c.ClientUDPSession == nil || (c.IsServer && c.ServerUDPSession == nil) {
return newError(CanNotUseUdpExtension)
return newError(CanNotUseUDPExtension)
}
if c.IsServer {
c.ServerUDPSession.CloseWithErr(nil)
Expand Down
Loading

0 comments on commit bff47c8

Please sign in to comment.