From 43447aa2e42a4d8bb316c770102a960d9f807b4d Mon Sep 17 00:00:00 2001 From: Loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com> Date: Sat, 27 Nov 2021 14:32:07 +0800 Subject: [PATCH] Chore: format code to fix lint (#1426) --- app/dispatcher/fakednssniffer.go | 3 +-- app/dns/dns.go | 1 - app/log/log.go | 1 - app/observatory/burst/burstobserver.go | 1 - app/reverse/portal.go | 2 +- app/router/strategy_leastload_test.go | 5 +++++ common/crypto/internal/chacha_core.generated.go | 2 +- common/environment/app.go | 2 -- common/environment/connection.go | 1 - common/environment/envimpl/fs.go | 3 +-- common/environment/proxy.go | 3 --- common/environment/transport.go | 2 -- common/interfaces.go | 1 - common/net/address.go | 1 - common/protocol/address.go | 1 - common/protocol/bittorrent/bittorrent.go | 3 +-- common/protocol/quic/sniff.go | 3 +-- common/registry/registry.go | 3 +-- common/serial/resolver.go | 3 +-- common/serial/typed_message.go | 2 ++ common/units/bytesize.go | 6 ++++-- features/extension/instance.go | 1 - features/extension/observatory.go | 1 - features/extension/storage.go | 1 - features/extension/storage/storage.go | 2 -- infra/conf/json/toml_test.go | 1 + infra/conf/json/yaml_test.go | 1 + infra/conf/merge/merge_test.go | 1 + infra/conf/merge/rules.go | 6 ++++-- infra/conf/synthetic/dns/dns.go | 1 - infra/conf/synthetic/router/router_strategy.go | 15 ++++++--------- infra/conf/v2jsonpb/follower.go | 4 ---- infra/conf/v2jsonpb/followerany.go | 2 ++ main/commands/all/api/balancer_info.go | 1 - main/commands/all/engineering/convertpb.go | 2 -- main/commands/all/engineering/engineering.go | 1 - main/commands/all/engineering/reversepb.go | 3 ++- main/commands/all/jsonv4/convert.go | 1 + main/commands/all/tls/ping.go | 4 +--- main/commands/all/verify.go | 4 +--- main/commands/base/command.go | 6 ++++-- main/distro/all/all.go | 2 +- main/v2binding/v2binding.go | 1 - proxy/freedom/freedom.go | 2 +- proxy/shadowsocks/protocol.go | 2 -- proxy/trojan/simplified/config.go | 17 +++++++++-------- v2ray_test.go | 2 +- 47 files changed, 55 insertions(+), 78 deletions(-) diff --git a/app/dispatcher/fakednssniffer.go b/app/dispatcher/fakednssniffer.go index d6f765d2c..2867eefff 100644 --- a/app/dispatcher/fakednssniffer.go +++ b/app/dispatcher/fakednssniffer.go @@ -86,8 +86,7 @@ func (f DNSThenOthersSniffResult) Domain() string { return f.domainName } -func newFakeDNSThenOthers(ctx context.Context, fakeDNSSniffer protocolSnifferWithMetadata, others []protocolSnifferWithMetadata) ( - protocolSnifferWithMetadata, error) { // nolint: unparam +func newFakeDNSThenOthers(ctx context.Context, fakeDNSSniffer protocolSnifferWithMetadata, others []protocolSnifferWithMetadata) (protocolSnifferWithMetadata, error) { // nolint: unparam // ctx may be used in the future _ = ctx return protocolSnifferWithMetadata{ diff --git a/app/dns/dns.go b/app/dns/dns.go index 8e894169e..46d679078 100644 --- a/app/dns/dns.go +++ b/app/dns/dns.go @@ -316,7 +316,6 @@ func init() { })) common.Must(common.RegisterConfig((*SimplifiedConfig)(nil), func(ctx context.Context, config interface{}) (interface{}, error) { - ctx = cfgcommon.NewConfigureLoadingContext(context.Background()) geoloadername := platform.NewEnvFlag("v2ray.conf.geoloader").GetValue(func() string { diff --git a/app/log/log.go b/app/log/log.go index b6efd091b..16b3c8ebe 100644 --- a/app/log/log.go +++ b/app/log/log.go @@ -23,7 +23,6 @@ type Instance struct { // New creates a new log.Instance based on the given config. func New(ctx context.Context, config *Config) (*Instance, error) { - if config.Error == nil { config.Error = &LogSpecification{Type: LogType_Console, Level: log.Severity_Warning} } diff --git a/app/observatory/burst/burstobserver.go b/app/observatory/burst/burstobserver.go index 16590031f..1a553e46d 100644 --- a/app/observatory/burst/burstobserver.go +++ b/app/observatory/burst/burstobserver.go @@ -66,7 +66,6 @@ func (o *Observer) Start() error { o.hp.StartScheduler(func() ([]string, error) { hs, ok := o.ohm.(outbound.HandlerSelector) if !ok { - return nil, newError("outbound.Manager is not a HandlerSelector") } diff --git a/app/reverse/portal.go b/app/reverse/portal.go index eef0f729d..9a6f57421 100644 --- a/app/reverse/portal.go +++ b/app/reverse/portal.go @@ -152,7 +152,7 @@ func (p *StaticMuxPicker) PickAvailable() (*mux.ClientWorker, error) { return nil, newError("empty worker list") } - var minIdx = -1 + minIdx := -1 var minConn uint32 = 9999 for i, w := range p.workers { if w.draining { diff --git a/app/router/strategy_leastload_test.go b/app/router/strategy_leastload_test.go index 5d1c28fa1..a3b05c06a 100644 --- a/app/router/strategy_leastload_test.go +++ b/app/router/strategy_leastload_test.go @@ -85,6 +85,7 @@ func TestSelectLeastExpected(t *testing.T) { t.Errorf("expected: %v, actual: %v", expected, len(ns)) } } + func TestSelectLeastExpected2(t *testing.T) { strategy := &LeastLoadStrategy{ settings: &StrategyLeastLoadConfig{ @@ -102,6 +103,7 @@ func TestSelectLeastExpected2(t *testing.T) { t.Errorf("expected: %v, actual: %v", expected, len(ns)) } } + func TestSelectLeastExpectedAndBaselines(t *testing.T) { strategy := &LeastLoadStrategy{ settings: &StrategyLeastLoadConfig{ @@ -122,6 +124,7 @@ func TestSelectLeastExpectedAndBaselines(t *testing.T) { t.Errorf("expected: %v, actual: %v", expected, len(ns)) } } + func TestSelectLeastExpectedAndBaselines2(t *testing.T) { strategy := &LeastLoadStrategy{ settings: &StrategyLeastLoadConfig{ @@ -142,6 +145,7 @@ func TestSelectLeastExpectedAndBaselines2(t *testing.T) { t.Errorf("expected: %v, actual: %v", expected, len(ns)) } } + func TestSelectLeastLoadBaselines(t *testing.T) { strategy := &LeastLoadStrategy{ settings: &StrategyLeastLoadConfig{ @@ -160,6 +164,7 @@ func TestSelectLeastLoadBaselines(t *testing.T) { t.Errorf("expected: %v, actual: %v", expected, len(ns)) } } + func TestSelectLeastLoadBaselinesNoQualified(t *testing.T) { strategy := &LeastLoadStrategy{ settings: &StrategyLeastLoadConfig{ diff --git a/common/crypto/internal/chacha_core.generated.go b/common/crypto/internal/chacha_core.generated.go index a0b59788e..654587768 100644 --- a/common/crypto/internal/chacha_core.generated.go +++ b/common/crypto/internal/chacha_core.generated.go @@ -3,7 +3,7 @@ package internal import "encoding/binary" func ChaCha20Block(s *[16]uint32, out []byte, rounds int) { - var x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15 = s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], s[8], s[9], s[10], s[11], s[12], s[13], s[14], s[15] + x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15 := s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], s[8], s[9], s[10], s[11], s[12], s[13], s[14], s[15] for i := 0; i < rounds; i += 2 { var x uint32 diff --git a/common/environment/app.go b/common/environment/app.go index b387c304f..7d4dd081b 100644 --- a/common/environment/app.go +++ b/common/environment/app.go @@ -9,14 +9,12 @@ type AppEnvironmentCapabilitySet interface { SystemNetworkCapabilitySet InstanceNetworkCapabilitySet FileSystemCapabilitySet - PersistentStorage() storage.ScopedPersistentStorage TransientStorage() storage.ScopedTransientStorage } type AppEnvironment interface { AppEnvironmentCapabilitySet - NarrowScope(key []byte) (AppEnvironment, error) doNotImpl() } diff --git a/common/environment/connection.go b/common/environment/connection.go index d0bddb5ef..8691b7570 100644 --- a/common/environment/connection.go +++ b/common/environment/connection.go @@ -8,7 +8,6 @@ type ConnectionCapabilitySet interface { type ConnectionEnvironment interface { ConnectionCapabilitySet - doNotImpl() } diff --git a/common/environment/envimpl/fs.go b/common/environment/envimpl/fs.go index ac39e1fbf..9d130a407 100644 --- a/common/environment/envimpl/fs.go +++ b/common/environment/envimpl/fs.go @@ -6,8 +6,7 @@ import ( "github.com/v2fly/v2ray-core/v4/common/platform/filesystem/fsifce" ) -type fileSystemDefaultImpl struct { -} +type fileSystemDefaultImpl struct{} func (f fileSystemDefaultImpl) OpenFileForReadSeek() fsifce.FileSeekerFunc { return filesystem.NewFileSeeker diff --git a/common/environment/proxy.go b/common/environment/proxy.go index d00b2c1e8..f46d9f69a 100644 --- a/common/environment/proxy.go +++ b/common/environment/proxy.go @@ -7,15 +7,12 @@ import ( type ProxyEnvironmentCapabilitySet interface { BaseEnvironmentCapabilitySet InstanceNetworkCapabilitySet - TransientStorage() storage.ScopedTransientStorage } type ProxyEnvironment interface { ProxyEnvironmentCapabilitySet - NarrowScope(key []byte) (ProxyEnvironment, error) NarrowScopeToTransport(key []byte) (TransportEnvironment, error) - doNotImpl() } diff --git a/common/environment/transport.go b/common/environment/transport.go index 9fa109eab..f026f2c0f 100644 --- a/common/environment/transport.go +++ b/common/environment/transport.go @@ -8,13 +8,11 @@ type TransportEnvironmentCapacitySet interface { BaseEnvironmentCapabilitySet SystemNetworkCapabilitySet InstanceNetworkCapabilitySet - TransientStorage() storage.ScopedTransientStorage } type TransportEnvironment interface { TransportEnvironmentCapacitySet - NarrowScope(key []byte) (TransportEnvironment, error) doNotImpl() } diff --git a/common/interfaces.go b/common/interfaces.go index cac2ac69c..299d65d67 100644 --- a/common/interfaces.go +++ b/common/interfaces.go @@ -42,7 +42,6 @@ func Interrupt(obj interface{}) error { type Runnable interface { // Start starts the runnable object. Upon the method returning nil, the object begins to function properly. Start() error - Closable } diff --git a/common/net/address.go b/common/net/address.go index 677449571..c4f623414 100644 --- a/common/net/address.go +++ b/common/net/address.go @@ -66,7 +66,6 @@ type Address interface { IP() net.IP // IP of this Address Domain() string // Domain of this Address Family() AddressFamily - String() string // String representation of this Address } diff --git a/common/protocol/address.go b/common/protocol/address.go index e98965e4b..e547d63ff 100644 --- a/common/protocol/address.go +++ b/common/protocol/address.go @@ -37,7 +37,6 @@ func WithAddressTypeParser(atp AddressTypeParser) AddressOption { type AddressSerializer interface { ReadAddressPort(buffer *buf.Buffer, input io.Reader) (net.Address, net.Port, error) - WriteAddressPort(writer io.Writer, addr net.Address, port net.Port) error } diff --git a/common/protocol/bittorrent/bittorrent.go b/common/protocol/bittorrent/bittorrent.go index 84b151166..26d800626 100644 --- a/common/protocol/bittorrent/bittorrent.go +++ b/common/protocol/bittorrent/bittorrent.go @@ -6,9 +6,8 @@ import ( "math" "time" - "github.com/v2fly/v2ray-core/v4/common/buf" - "github.com/v2fly/v2ray-core/v4/common" + "github.com/v2fly/v2ray-core/v4/common/buf" ) type SniffHeader struct{} diff --git a/common/protocol/quic/sniff.go b/common/protocol/quic/sniff.go index db42e7a28..776e6283b 100644 --- a/common/protocol/quic/sniff.go +++ b/common/protocol/quic/sniff.go @@ -7,14 +7,13 @@ import ( "encoding/binary" "io" - "github.com/v2fly/v2ray-core/v4/common/errors" - "github.com/lucas-clemente/quic-go/quicvarint" "github.com/marten-seemann/qtls-go1-17" "golang.org/x/crypto/hkdf" "github.com/v2fly/v2ray-core/v4/common" "github.com/v2fly/v2ray-core/v4/common/buf" + "github.com/v2fly/v2ray-core/v4/common/errors" ptls "github.com/v2fly/v2ray-core/v4/common/protocol/tls" ) diff --git a/common/registry/registry.go b/common/registry/registry.go index c22eea373..cc5cde5a4 100644 --- a/common/registry/registry.go +++ b/common/registry/registry.go @@ -77,7 +77,6 @@ func (i *implementationRegistry) LoadImplementationByAlias(ctx context.Context, } return implementationConfigInstance.(proto.Message), nil - } func newImplementationRegistry() *implementationRegistry { @@ -107,7 +106,7 @@ func RegisterImplementation(proto interface{}, loader CustomLoader) error { func registerImplementation(proto interface{}, loader CustomLoader) error { protoReflect := reflect.New(reflect.TypeOf(proto).Elem()) - var proto2 = protoReflect.Interface().(protov2.Message) + proto2 := protoReflect.Interface().(protov2.Message) msgDesc := proto2.ProtoReflect().Descriptor() fullName := string(msgDesc.FullName()) msgOpts, err := protoext.GetMessageOptions(msgDesc) diff --git a/common/serial/resolver.go b/common/serial/resolver.go index 1075b0cda..6e12a39b4 100644 --- a/common/serial/resolver.go +++ b/common/serial/resolver.go @@ -8,8 +8,7 @@ type AnyResolver interface { Resolve(typeURL string) (proto.Message, error) } -type serialResolver struct { -} +type serialResolver struct{} func (s serialResolver) Resolve(typeURL string) (proto.Message, error) { instance, err := GetInstance(typeURL) diff --git a/common/serial/typed_message.go b/common/serial/typed_message.go index b3102fb80..f10332232 100644 --- a/common/serial/typed_message.go +++ b/common/serial/typed_message.go @@ -52,9 +52,11 @@ func GetInstanceOf(v *anypb.Any) (proto.Message, error) { func V2Type(v *anypb.Any) string { return V2TypeFromURL(v.TypeUrl) } + func V2TypeFromURL(string2 string) string { return strings.TrimPrefix(string2, V2RayTypeURLHeader) } + func V2TypeHumanReadable(v *anypb.Any) string { return v.TypeUrl } diff --git a/common/units/bytesize.go b/common/units/bytesize.go index be0a2b60f..bf3c84d32 100644 --- a/common/units/bytesize.go +++ b/common/units/bytesize.go @@ -7,8 +7,10 @@ import ( "unicode" ) -var errInvalidSize = errors.New("invalid size") -var errInvalidUnit = errors.New("invalid or unsupported unit") +var ( + errInvalidSize = errors.New("invalid size") + errInvalidUnit = errors.New("invalid or unsupported unit") +) // ByteSize is the size of bytes type ByteSize uint64 diff --git a/features/extension/instance.go b/features/extension/instance.go index 3cde039d5..f31762524 100644 --- a/features/extension/instance.go +++ b/features/extension/instance.go @@ -9,7 +9,6 @@ import ( // InstanceManagement : unstable type InstanceManagement interface { features.Feature - ListInstance(ctx context.Context) ([]string, error) AddInstance(ctx context.Context, name string, config []byte, configType string) error StartInstance(ctx context.Context, name string) error diff --git a/features/extension/observatory.go b/features/extension/observatory.go index 3c0d1a308..55b327b83 100644 --- a/features/extension/observatory.go +++ b/features/extension/observatory.go @@ -10,7 +10,6 @@ import ( type Observatory interface { features.Feature - GetObservation(ctx context.Context) (proto.Message, error) } diff --git a/features/extension/storage.go b/features/extension/storage.go index 076bfe338..f3ef432d5 100644 --- a/features/extension/storage.go +++ b/features/extension/storage.go @@ -8,7 +8,6 @@ import ( type PersistentStorageEngine interface { features.Feature - PersistentStorageEngine() Put(ctx context.Context, key []byte, value []byte) error Get(ctx context.Context, key []byte) ([]byte, error) diff --git a/features/extension/storage/storage.go b/features/extension/storage/storage.go index a3524a2d4..d53cdb86f 100644 --- a/features/extension/storage/storage.go +++ b/features/extension/storage/storage.go @@ -6,11 +6,9 @@ import ( type ScopedPersistentStorage interface { ScopedPersistentStorageEngine() - Put(ctx context.Context, key []byte, value []byte) error Get(ctx context.Context, key []byte) ([]byte, error) List(ctx context.Context, keyPrefix []byte) ([][]byte, error) - ClearIfCharacteristicMismatch(ctx context.Context, characteristic []byte) error NarrowScope(ctx context.Context, key []byte) (ScopedPersistentStorage, error) } diff --git a/infra/conf/json/toml_test.go b/infra/conf/json/toml_test.go index fbff5a894..2c3c27332 100644 --- a/infra/conf/json/toml_test.go +++ b/infra/conf/json/toml_test.go @@ -70,6 +70,7 @@ security = 'tls' json.Unmarshal(bs, &m) assertResult(t, m, expected) } + func TestTOMLToJSON_ValueTypes(t *testing.T) { input := ` boolean = [ true, false, true, false ] diff --git a/infra/conf/json/yaml_test.go b/infra/conf/json/yaml_test.go index 84ada0a86..1d5f36ead 100644 --- a/infra/conf/json/yaml_test.go +++ b/infra/conf/json/yaml_test.go @@ -67,6 +67,7 @@ outbounds: json.Unmarshal(bs, &m) assertResult(t, m, expected) } + func TestYMLToJSON_ValueTypes(t *testing.T) { input := ` boolean: diff --git a/infra/conf/merge/merge_test.go b/infra/conf/merge/merge_test.go index 5c1f6e9f3..49beafce4 100644 --- a/infra/conf/merge/merge_test.go +++ b/infra/conf/merge/merge_test.go @@ -193,6 +193,7 @@ func TestMergeTagDeep(t *testing.T) { } assertResult(t, m, expected) } + func assertResult(t *testing.T, value []byte, expected string) { v := make(map[string]interface{}) err := serial.DecodeJSON(bytes.NewReader(value), &v) diff --git a/infra/conf/merge/rules.go b/infra/conf/merge/rules.go index 4ab51d922..5ba3f909a 100644 --- a/infra/conf/merge/rules.go +++ b/infra/conf/merge/rules.go @@ -4,8 +4,10 @@ package merge -const priorityKey string = "_priority" -const tagKey string = "_tag" +const ( + priorityKey string = "_priority" + tagKey string = "_tag" +) // ApplyRules applies merge rules according to _tag, _priority fields, and remove them func ApplyRules(m map[string]interface{}) error { diff --git a/infra/conf/synthetic/dns/dns.go b/infra/conf/synthetic/dns/dns.go index 5e9f85855..d685bc70d 100644 --- a/infra/conf/synthetic/dns/dns.go +++ b/infra/conf/synthetic/dns/dns.go @@ -204,7 +204,6 @@ func (c *DNSConfig) BuildV5(ctx context.Context) (*dns.Config, error) { // Build implements Buildable func (c *DNSConfig) Build() (*dns.Config, error) { - if c.cfgctx == nil { c.cfgctx = cfgcommon.NewConfigureLoadingContext(context.Background()) diff --git a/infra/conf/synthetic/router/router_strategy.go b/infra/conf/synthetic/router/router_strategy.go index 613ce612c..bcbc13b83 100644 --- a/infra/conf/synthetic/router/router_strategy.go +++ b/infra/conf/synthetic/router/router_strategy.go @@ -15,16 +15,13 @@ const ( strategyLeastPing string = "leastping" ) -var ( - strategyConfigLoader = loader.NewJSONConfigLoader(loader.ConfigCreatorCache{ - strategyRandom: func() interface{} { return new(strategyEmptyConfig) }, - strategyLeastLoad: func() interface{} { return new(strategyLeastLoadConfig) }, - strategyLeastPing: func() interface{} { return new(strategyLeastPingConfig) }, - }, "type", "settings") -) +var strategyConfigLoader = loader.NewJSONConfigLoader(loader.ConfigCreatorCache{ + strategyRandom: func() interface{} { return new(strategyEmptyConfig) }, + strategyLeastLoad: func() interface{} { return new(strategyLeastLoadConfig) }, + strategyLeastPing: func() interface{} { return new(strategyLeastPingConfig) }, +}, "type", "settings") -type strategyEmptyConfig struct { -} +type strategyEmptyConfig struct{} func (v *strategyEmptyConfig) Build() (proto.Message, error) { return nil, nil diff --git a/infra/conf/v2jsonpb/follower.go b/infra/conf/v2jsonpb/follower.go index 5d7512c10..86e4d2920 100644 --- a/infra/conf/v2jsonpb/follower.go +++ b/infra/conf/v2jsonpb/follower.go @@ -33,7 +33,6 @@ func (v *V2JsonProtobufFollower) Range(f func(protoreflect.FieldDescriptor, prot name := descriptor.FullName() fullname := v.Message.Descriptor().FullName() if fullname == "google.protobuf.Any" { - switch name { case "google.protobuf.Any.type_url": fd := V2JsonProtobufAnyTypeFieldDescriptor{descriptor} @@ -58,7 +57,6 @@ func (v *V2JsonProtobufFollower) Range(f func(protoreflect.FieldDescriptor, prot default: panic("unexpected any value") } - } return followValue(descriptor, value, f) }) @@ -106,7 +104,6 @@ func (v *V2JsonProtobufFollower) Set(descriptor protoreflect.FieldDescriptor, va default: v.Message.Set(descriptor, value) } - } func (v *V2JsonProtobufFollower) Mutable(descriptor protoreflect.FieldDescriptor) protoreflect.Value { @@ -124,7 +121,6 @@ func (v *V2JsonProtobufFollower) Mutable(descriptor protoreflect.FieldDescriptor } func (v *V2JsonProtobufFollower) NewField(descriptor protoreflect.FieldDescriptor) protoreflect.Value { - if _, ok := descriptor.(*V2JsonProtobufAnyValueField); ok { url := v.Message.Get(v.Message.Descriptor().Fields().ByName("type_url")).String() diff --git a/infra/conf/v2jsonpb/followerany.go b/infra/conf/v2jsonpb/followerany.go index 458acaab0..95d12a71f 100644 --- a/infra/conf/v2jsonpb/followerany.go +++ b/infra/conf/v2jsonpb/followerany.go @@ -54,6 +54,7 @@ type V2JsonProtobufAnyTypeFieldDescriptor struct { func (v V2JsonProtobufAnyTypeFieldDescriptor) JSONName() string { return "type" } + func (v V2JsonProtobufAnyTypeFieldDescriptor) TextName() string { return "type" } @@ -70,6 +71,7 @@ func (v *V2JsonProtobufAnyValueField) Kind() protoreflect.Kind { func (v *V2JsonProtobufAnyValueField) JSONName() string { return v.name } + func (v *V2JsonProtobufAnyValueField) TextName() string { return v.name } diff --git a/main/commands/all/api/balancer_info.go b/main/commands/all/api/balancer_info.go index bb7d47f97..e74e35551 100644 --- a/main/commands/all/api/balancer_info.go +++ b/main/commands/all/api/balancer_info.go @@ -60,7 +60,6 @@ func executeBalancerInfo(cmd *base.Command, args []string) { } showBalancerInfo(resp.Balancer) - } func showBalancerInfo(b *routerService.BalancerMsg) { diff --git a/main/commands/all/engineering/convertpb.go b/main/commands/all/engineering/convertpb.go index 3786099e1..13c1eebd2 100644 --- a/main/commands/all/engineering/convertpb.go +++ b/main/commands/all/engineering/convertpb.go @@ -46,7 +46,6 @@ var cmdConvertPb = &base.Command{ base.Fatalf("%s", newError(fmt.Sprintf("failed to load config: %s", configFiles)).Base(err)) return } - } bytew, err := proto.Marshal(config) if err != nil { @@ -54,6 +53,5 @@ var cmdConvertPb = &base.Command{ return } io.Copy(os.Stdout, bytes.NewReader(bytew)) - }, } diff --git a/main/commands/all/engineering/engineering.go b/main/commands/all/engineering/engineering.go index f5c0fb78e..4e754c727 100644 --- a/main/commands/all/engineering/engineering.go +++ b/main/commands/all/engineering/engineering.go @@ -14,5 +14,4 @@ var cmdEngineering = &base.Command{ func init() { base.RegisterCommand(cmdEngineering) - } diff --git a/main/commands/all/engineering/reversepb.go b/main/commands/all/engineering/reversepb.go index 91c58fb6b..7682338bf 100644 --- a/main/commands/all/engineering/reversepb.go +++ b/main/commands/all/engineering/reversepb.go @@ -41,4 +41,5 @@ var cmdReversePb = &base.Command{ io.Copy(os.Stdout, bytes.NewReader(value)) } } - }} + }, +} diff --git a/main/commands/all/jsonv4/convert.go b/main/commands/all/jsonv4/convert.go index c549a9773..32ac9c723 100644 --- a/main/commands/all/jsonv4/convert.go +++ b/main/commands/all/jsonv4/convert.go @@ -74,6 +74,7 @@ func setConfArgs(cmd *base.Command) { cmd.Flag.StringVar(&outputFormat, "o", "json", "") cmd.Flag.BoolVar(&confDirRecursively, "r", false, "") } + func executeConvert(cmd *base.Command, args []string) { setConfArgs(cmd) cmd.Flag.Parse(args) diff --git a/main/commands/all/tls/ping.go b/main/commands/all/tls/ping.go index 1f4d4fbec..ae6b62ff2 100644 --- a/main/commands/all/tls/ping.go +++ b/main/commands/all/tls/ping.go @@ -29,9 +29,7 @@ func init() { cmdPing.Run = executePing // break init loop } -var ( - pingIPStr = cmdPing.Flag.String("ip", "", "") -) +var pingIPStr = cmdPing.Flag.String("ip", "", "") func executePing(cmd *base.Command, args []string) { if cmdPing.Flag.NArg() < 1 { diff --git a/main/commands/all/verify.go b/main/commands/all/verify.go index 0fcdfcabc..63636f3ba 100644 --- a/main/commands/all/verify.go +++ b/main/commands/all/verify.go @@ -25,9 +25,7 @@ func init() { cmdVerify.Run = executeVerify // break init loop } -var ( - verifySigFile = cmdVerify.Flag.String("sig", "", "Path to the signature file") -) +var verifySigFile = cmdVerify.Flag.String("sig", "", "Path to the signature file") func executeVerify(cmd *base.Command, args []string) { target := cmdVerify.Flag.Arg(0) diff --git a/main/commands/base/command.go b/main/commands/base/command.go index 123453d50..e2f106589 100644 --- a/main/commands/base/command.go +++ b/main/commands/base/command.go @@ -113,8 +113,10 @@ func ExitIfErrors() { } } -var exitStatus = 0 -var exitMu sync.Mutex +var ( + exitStatus = 0 + exitMu sync.Mutex +) // SetExitStatus set exit status code func SetExitStatus(n int) { diff --git a/main/distro/all/all.go b/main/distro/all/all.go index 078d01dc7..19f30dd1f 100644 --- a/main/distro/all/all.go +++ b/main/distro/all/all.go @@ -79,7 +79,7 @@ import ( // commands _ "github.com/v2fly/v2ray-core/v4/main/commands/all" - //engineering commands + // engineering commands _ "github.com/v2fly/v2ray-core/v4/main/commands/all/engineering" // Commands that rely on jsonv4 format This disable selective compile diff --git a/main/v2binding/v2binding.go b/main/v2binding/v2binding.go index 70d2e6685..c00df1658 100644 --- a/main/v2binding/v2binding.go +++ b/main/v2binding/v2binding.go @@ -25,7 +25,6 @@ type bindingInstance struct { var binding bindingInstance func (b *bindingInstance) startAPIInstance() { - bindConfig := &core.Config{ App: []*anypb.Any{ serial.ToTypedMessage(&instman.Config{}), diff --git a/proxy/freedom/freedom.go b/proxy/freedom/freedom.go index 6e14b3bd2..a4a84a178 100644 --- a/proxy/freedom/freedom.go +++ b/proxy/freedom/freedom.go @@ -71,7 +71,7 @@ func (h *Handler) resolveIP(ctx context.Context, domain string, localAddr net.Ad newError("DNS client doesn't implement ClientWithIPOption") } - var lookupFunc = h.dns.LookupIP + lookupFunc := h.dns.LookupIP if h.config.DomainStrategy == Config_USE_IP4 || (localAddr != nil && localAddr.Family().IsIPv4()) { if lookupIPv4, ok := h.dns.(dns.IPv4Lookup); ok { lookupFunc = lookupIPv4.LookupIPv4 diff --git a/proxy/shadowsocks/protocol.go b/proxy/shadowsocks/protocol.go index f806442f9..6c0c54f96 100644 --- a/proxy/shadowsocks/protocol.go +++ b/proxy/shadowsocks/protocol.go @@ -37,7 +37,6 @@ func ReadTCPSession(user *protocol.MemoryUser, reader io.Reader) (*protocol.Requ behaviorSeed := crc32.ChecksumIEEE(hashkdf.Sum(nil)) drainer, err := drain.NewBehaviorSeedLimitedDrainer(int64(behaviorSeed), 16+38, 3266, 64) - if err != nil { return nil, nil, newError("failed to initialize drainer").Base(err) } @@ -138,7 +137,6 @@ func ReadTCPResponse(user *protocol.MemoryUser, reader io.Reader) (buf.Reader, e behaviorSeed := crc32.ChecksumIEEE(hashkdf.Sum(nil)) drainer, err := drain.NewBehaviorSeedLimitedDrainer(int64(behaviorSeed), 16+38, 3266, 64) - if err != nil { return nil, newError("failed to initialize drainer").Base(err) } diff --git a/proxy/trojan/simplified/config.go b/proxy/trojan/simplified/config.go index 31f476121..f2b0b2435 100644 --- a/proxy/trojan/simplified/config.go +++ b/proxy/trojan/simplified/config.go @@ -28,17 +28,18 @@ func init() { common.Must(common.RegisterConfig((*ClientConfig)(nil), func(ctx context.Context, config interface{}) (interface{}, error) { simplifiedClient := config.(*ClientConfig) - fullClient := &trojan.ClientConfig{Server: []*protocol.ServerEndpoint{ - { - Address: simplifiedClient.Address, - Port: simplifiedClient.Port, - User: []*protocol.User{ - { - Account: serial.ToTypedMessage(&trojan.Account{Password: simplifiedClient.Password}), + fullClient := &trojan.ClientConfig{ + Server: []*protocol.ServerEndpoint{ + { + Address: simplifiedClient.Address, + Port: simplifiedClient.Port, + User: []*protocol.User{ + { + Account: serial.ToTypedMessage(&trojan.Account{Password: simplifiedClient.Password}), + }, }, }, }, - }, } return common.CreateObject(ctx, fullClient) })) diff --git a/v2ray_test.go b/v2ray_test.go index f408a8a13..e87ca79d1 100644 --- a/v2ray_test.go +++ b/v2ray_test.go @@ -1,10 +1,10 @@ package core_test import ( - "google.golang.org/protobuf/types/known/anypb" "testing" "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/types/known/anypb" . "github.com/v2fly/v2ray-core/v4" "github.com/v2fly/v2ray-core/v4/app/dispatcher"