From dce8764fd7c69a67b3f58b0a5acac9762ae385cc Mon Sep 17 00:00:00 2001 From: Loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com> Date: Sat, 27 Nov 2021 17:16:41 +0800 Subject: [PATCH] Lint: fix lint (#1427) * Lint: replace golint with revive * Lint: fix lint --- .github/linters/.golangci.yml | 4 +- app/commander/commander.go | 2 +- app/dns/dns.go | 4 +- app/instman/instman.go | 2 +- app/observatory/burst/burst.go | 6 +- app/observatory/burst/burstobserver.go | 2 +- .../config.pb.go | 68 +++---- .../config.proto | 8 +- .../muti.go => multiobservatory/multi.go} | 4 +- app/restful-api/config.pb.go | 175 ------------------ app/{restful-api => restfulapi}/config.go | 2 +- app/restfulapi/config.pb.go | 174 +++++++++++++++++ app/{restful-api => restfulapi}/config.proto | 6 +- .../errors.generated.go | 2 +- .../restful_api.go} | 2 +- app/{restful-api => restfulapi}/service.go | 2 +- .../service_test.go | 2 +- app/router/config.go | 2 +- app/router/router.go | 1 - app/router/strategy_leastload.go | 39 ++-- common/cmdarg/arg.go | 5 +- common/environment/envctx/env.go | 5 +- common/net/network.go | 2 +- common/protoext/extensions.go | 16 +- common/protofilter/filter.go | 8 +- common/session/context.go | 2 +- common/taggedfeatures/configloader.go | 4 +- config.go | 3 +- infra/conf/json/toml.go | 2 +- infra/conf/jsonpb/jsonpb.go | 12 +- infra/conf/serial/loader.go | 2 +- infra/conf/synthetic/dns/dns.go | 3 +- infra/conf/synthetic/log/log.go | 2 +- infra/conf/synthetic/router/router.go | 4 +- infra/conf/v2jsonpb/follower.go | 10 +- infra/conf/v4/blackhole_test.go | 2 +- infra/conf/v4/dns_proxy_test.go | 2 +- infra/conf/v4/dokodemo_test.go | 2 +- infra/conf/v4/freedom_test.go | 2 +- infra/conf/v4/http_test.go | 2 +- infra/conf/v4/observatory.go | 11 +- infra/conf/v4/policy_test.go | 2 +- infra/conf/v4/reverse_test.go | 2 +- infra/conf/v4/shadowsocks_test.go | 2 +- infra/conf/v4/socks_test.go | 2 +- infra/conf/v4/transport_test.go | 2 +- infra/conf/v4/v2ray.go | 2 +- infra/conf/v4/v2ray_test.go | 2 +- infra/conf/v4/vless_test.go | 2 +- infra/conf/v4/vmess_test.go | 2 +- infra/conf/v5cfg/common.go | 14 +- infra/conf/v5cfg/inbound.go | 2 +- infra/conf/v5cfg/init.go | 4 +- infra/conf/v5cfg/outbound.go | 2 +- infra/conf/v5cfg/root.go | 10 +- infra/conf/v5cfg/stream.go | 4 +- main/commands/all/api/shared.go | 2 +- main/commands/all/engineering/convertpb.go | 6 +- main/commands/all/engineering/reversepb.go | 2 +- main/commands/all/jsonv4/convert.go | 2 +- main/commands/helpers/config_load.go | 2 +- main/distro/all/all.go | 3 +- main/v2binding/v2binding.go | 3 +- proxy/shadowsocks/protocol.go | 2 +- proxy/vmess/encoding/client.go | 8 +- transport/internet/headers/http/http.go | 2 +- transport/internet/kcp/io.go | 4 +- transport/internet/sockopt_darwin.go | 6 +- transport/internet/sockopt_linux.go | 4 +- transport/internet/sockopt_windows.go | 2 +- transport/internet/system_listener.go | 2 +- transport/internet/tcp/sockopt_linux.go | 2 +- 72 files changed, 346 insertions(+), 368 deletions(-) rename app/observatory/{multiObservatory => multiobservatory}/config.pb.go (71%) rename app/observatory/{multiObservatory => multiobservatory}/config.proto (85%) rename app/observatory/{multiObservatory/muti.go => multiobservatory/multi.go} (93%) delete mode 100644 app/restful-api/config.pb.go rename app/{restful-api => restfulapi}/config.go (92%) create mode 100644 app/restfulapi/config.pb.go rename app/{restful-api => restfulapi}/config.proto (82%) rename app/{restful-api => restfulapi}/errors.generated.go (91%) rename app/{restful-api/restful-api.go => restfulapi/restful_api.go} (99%) rename app/{restful-api => restfulapi}/service.go (98%) rename app/{restful-api => restfulapi}/service_test.go (93%) diff --git a/.github/linters/.golangci.yml b/.github/linters/.golangci.yml index 22829352e..de49f0198 100644 --- a/.github/linters/.golangci.yml +++ b/.github/linters/.golangci.yml @@ -7,7 +7,7 @@ issues: new: true exclude-rules: - linters: - - staticcheck + - staticcheck text: "SA1019:" linters: @@ -19,13 +19,13 @@ linters: - gofmt - gofumpt - goimports - - golint - goprintffuncname - gosimple - govet - ineffassign - misspell - nakedret + - revive - rowserrcheck - staticcheck - structcheck diff --git a/app/commander/commander.go b/app/commander/commander.go index 49a515d72..2d98da2e7 100644 --- a/app/commander/commander.go +++ b/app/commander/commander.go @@ -117,7 +117,7 @@ func init() { Service: nil, } for _, v := range simplifiedConfig.Name { - pack, err := v5cfg.LoadHeterogeneousConfigFromRawJson(ctx, "grpcservice", v, []byte("{}")) + pack, err := v5cfg.LoadHeterogeneousConfigFromRawJSON(ctx, "grpcservice", v, []byte("{}")) if err != nil { return nil, err } diff --git a/app/dns/dns.go b/app/dns/dns.go index 46d679078..b7c4f59e5 100644 --- a/app/dns/dns.go +++ b/app/dns/dns.go @@ -315,8 +315,8 @@ func init() { return New(ctx, config.(*Config)) })) - common.Must(common.RegisterConfig((*SimplifiedConfig)(nil), func(ctx context.Context, config interface{}) (interface{}, error) { - ctx = cfgcommon.NewConfigureLoadingContext(context.Background()) + common.Must(common.RegisterConfig((*SimplifiedConfig)(nil), func(ctx context.Context, config interface{}) (interface{}, error) { // nolint: staticcheck + ctx = cfgcommon.NewConfigureLoadingContext(context.Background()) // nolint: staticcheck geoloadername := platform.NewEnvFlag("v2ray.conf.geoloader").GetValue(func() string { return "standard" diff --git a/app/instman/instman.go b/app/instman/instman.go index d703cf885..e2d007f96 100644 --- a/app/instman/instman.go +++ b/app/instman/instman.go @@ -11,7 +11,7 @@ import ( //go:generate go run github.com/v2fly/v2ray-core/v4/common/errors/errorgen type InstanceMgr struct { - config *Config + config *Config // nolint: structcheck instances map[string]*core.Instance } diff --git a/app/observatory/burst/burst.go b/app/observatory/burst/burst.go index 13eb0fd60..be3bc7265 100644 --- a/app/observatory/burst/burst.go +++ b/app/observatory/burst/burst.go @@ -8,7 +8,7 @@ import ( //go:generate go run github.com/v2fly/v2ray-core/v4/common/errors/errorgen const ( - rttFailed = time.Duration(math.MaxInt64 - iota) - rttUntested - rttUnqualified + rttFailed = time.Duration(math.MaxInt64 - iota) + rttUntested // nolint: varcheck + rttUnqualified // nolint: varcheck ) diff --git a/app/observatory/burst/burstobserver.go b/app/observatory/burst/burstobserver.go index 1a553e46d..ab4ca5bef 100644 --- a/app/observatory/burst/burstobserver.go +++ b/app/observatory/burst/burstobserver.go @@ -18,7 +18,7 @@ type Observer struct { config *Config ctx context.Context - statusLock sync.Mutex + statusLock sync.Mutex // nolint: structcheck hp *HealthPing finished *done.Instance diff --git a/app/observatory/multiObservatory/config.pb.go b/app/observatory/multiobservatory/config.pb.go similarity index 71% rename from app/observatory/multiObservatory/config.pb.go rename to app/observatory/multiobservatory/config.pb.go index 275638df8..81c0f41c0 100644 --- a/app/observatory/multiObservatory/config.pb.go +++ b/app/observatory/multiobservatory/config.pb.go @@ -2,9 +2,9 @@ // versions: // protoc-gen-go v1.27.1 // protoc v3.17.3 -// source: app/observatory/multiObservatory/config.proto +// source: app/observatory/multiobservatory/config.proto -package multiObservatory +package multiobservatory import ( _ "github.com/v2fly/v2ray-core/v4/common/protoext" @@ -33,7 +33,7 @@ type Config struct { func (x *Config) Reset() { *x = Config{} if protoimpl.UnsafeEnabled { - mi := &file_app_observatory_multiObservatory_config_proto_msgTypes[0] + mi := &file_app_observatory_multiobservatory_config_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -46,7 +46,7 @@ func (x *Config) String() string { func (*Config) ProtoMessage() {} func (x *Config) ProtoReflect() protoreflect.Message { - mi := &file_app_observatory_multiObservatory_config_proto_msgTypes[0] + mi := &file_app_observatory_multiobservatory_config_proto_msgTypes[0] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -59,7 +59,7 @@ func (x *Config) ProtoReflect() protoreflect.Message { // Deprecated: Use Config.ProtoReflect.Descriptor instead. func (*Config) Descriptor() ([]byte, []int) { - return file_app_observatory_multiObservatory_config_proto_rawDescGZIP(), []int{0} + return file_app_observatory_multiobservatory_config_proto_rawDescGZIP(), []int{0} } func (x *Config) GetHolders() *taggedfeatures.Config { @@ -69,15 +69,15 @@ func (x *Config) GetHolders() *taggedfeatures.Config { return nil } -var File_app_observatory_multiObservatory_config_proto protoreflect.FileDescriptor +var File_app_observatory_multiobservatory_config_proto protoreflect.FileDescriptor -var file_app_observatory_multiObservatory_config_proto_rawDesc = []byte{ +var file_app_observatory_multiobservatory_config_proto_rawDesc = []byte{ 0x0a, 0x2d, 0x61, 0x70, 0x70, 0x2f, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x6f, 0x72, - 0x79, 0x2f, 0x6d, 0x75, 0x6c, 0x74, 0x69, 0x4f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x6f, + 0x79, 0x2f, 0x6d, 0x75, 0x6c, 0x74, 0x69, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x6f, 0x72, 0x79, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x2b, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x6f, 0x72, 0x79, 0x2e, 0x6d, 0x75, 0x6c, 0x74, - 0x69, 0x4f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x6f, 0x72, 0x79, 0x1a, 0x24, 0x63, 0x6f, + 0x69, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x6f, 0x72, 0x79, 0x1a, 0x24, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x74, 0x61, 0x67, 0x67, 0x65, 0x64, 0x66, 0x65, 0x61, 0x74, 0x75, 0x72, 0x65, 0x73, 0x2f, 0x73, 0x6b, 0x65, 0x6c, 0x65, 0x74, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x20, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, @@ -88,7 +88,7 @@ var file_app_observatory_multiObservatory_config_proto_rawDesc = []byte{ 0x6d, 0x6f, 0x6e, 0x2e, 0x74, 0x61, 0x67, 0x67, 0x65, 0x64, 0x66, 0x65, 0x61, 0x74, 0x75, 0x72, 0x65, 0x73, 0x2e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x07, 0x68, 0x6f, 0x6c, 0x64, 0x65, 0x72, 0x73, 0x3a, 0x23, 0x82, 0xb5, 0x18, 0x09, 0x0a, 0x07, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, - 0x65, 0x82, 0xb5, 0x18, 0x12, 0x12, 0x10, 0x6d, 0x75, 0x6c, 0x74, 0x69, 0x4f, 0x62, 0x73, 0x65, + 0x65, 0x82, 0xb5, 0x18, 0x12, 0x12, 0x10, 0x6d, 0x75, 0x6c, 0x74, 0x69, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x6f, 0x72, 0x79, 0x42, 0xa2, 0x01, 0x0a, 0x2f, 0x63, 0x6f, 0x6d, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x6f, 0x72, 0x79, 0x2e, 0x6d, 0x75, 0x6c, 0x74, 0x69, @@ -96,7 +96,7 @@ var file_app_observatory_multiObservatory_config_proto_rawDesc = []byte{ 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x76, 0x32, 0x66, 0x6c, 0x79, 0x2f, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2d, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x76, 0x34, 0x2f, 0x61, 0x70, 0x70, 0x2f, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x6f, 0x72, 0x79, 0x2f, 0x6d, 0x75, - 0x6c, 0x74, 0x69, 0x4f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x6f, 0x72, 0x79, 0xaa, 0x02, + 0x6c, 0x74, 0x69, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x6f, 0x72, 0x79, 0xaa, 0x02, 0x2b, 0x56, 0x32, 0x52, 0x61, 0x79, 0x2e, 0x43, 0x6f, 0x72, 0x65, 0x2e, 0x41, 0x70, 0x70, 0x2e, 0x4f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x6f, 0x72, 0x79, 0x2e, 0x4d, 0x75, 0x6c, 0x74, 0x69, 0x4f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x6f, 0x72, 0x79, 0x62, 0x06, 0x70, 0x72, @@ -104,24 +104,24 @@ var file_app_observatory_multiObservatory_config_proto_rawDesc = []byte{ } var ( - file_app_observatory_multiObservatory_config_proto_rawDescOnce sync.Once - file_app_observatory_multiObservatory_config_proto_rawDescData = file_app_observatory_multiObservatory_config_proto_rawDesc + file_app_observatory_multiobservatory_config_proto_rawDescOnce sync.Once + file_app_observatory_multiobservatory_config_proto_rawDescData = file_app_observatory_multiobservatory_config_proto_rawDesc ) -func file_app_observatory_multiObservatory_config_proto_rawDescGZIP() []byte { - file_app_observatory_multiObservatory_config_proto_rawDescOnce.Do(func() { - file_app_observatory_multiObservatory_config_proto_rawDescData = protoimpl.X.CompressGZIP(file_app_observatory_multiObservatory_config_proto_rawDescData) +func file_app_observatory_multiobservatory_config_proto_rawDescGZIP() []byte { + file_app_observatory_multiobservatory_config_proto_rawDescOnce.Do(func() { + file_app_observatory_multiobservatory_config_proto_rawDescData = protoimpl.X.CompressGZIP(file_app_observatory_multiobservatory_config_proto_rawDescData) }) - return file_app_observatory_multiObservatory_config_proto_rawDescData + return file_app_observatory_multiobservatory_config_proto_rawDescData } -var file_app_observatory_multiObservatory_config_proto_msgTypes = make([]protoimpl.MessageInfo, 1) -var file_app_observatory_multiObservatory_config_proto_goTypes = []interface{}{ - (*Config)(nil), // 0: v2ray.core.app.observatory.multiObservatory.Config +var file_app_observatory_multiobservatory_config_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_app_observatory_multiobservatory_config_proto_goTypes = []interface{}{ + (*Config)(nil), // 0: v2ray.core.app.observatory.multiobservatory.Config (*taggedfeatures.Config)(nil), // 1: v2ray.core.common.taggedfeatures.Config } -var file_app_observatory_multiObservatory_config_proto_depIdxs = []int32{ - 1, // 0: v2ray.core.app.observatory.multiObservatory.Config.holders:type_name -> v2ray.core.common.taggedfeatures.Config +var file_app_observatory_multiobservatory_config_proto_depIdxs = []int32{ + 1, // 0: v2ray.core.app.observatory.multiobservatory.Config.holders:type_name -> v2ray.core.common.taggedfeatures.Config 1, // [1:1] is the sub-list for method output_type 1, // [1:1] is the sub-list for method input_type 1, // [1:1] is the sub-list for extension type_name @@ -129,13 +129,13 @@ var file_app_observatory_multiObservatory_config_proto_depIdxs = []int32{ 0, // [0:1] is the sub-list for field type_name } -func init() { file_app_observatory_multiObservatory_config_proto_init() } -func file_app_observatory_multiObservatory_config_proto_init() { - if File_app_observatory_multiObservatory_config_proto != nil { +func init() { file_app_observatory_multiobservatory_config_proto_init() } +func file_app_observatory_multiobservatory_config_proto_init() { + if File_app_observatory_multiobservatory_config_proto != nil { return } if !protoimpl.UnsafeEnabled { - file_app_observatory_multiObservatory_config_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + file_app_observatory_multiobservatory_config_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Config); i { case 0: return &v.state @@ -152,18 +152,18 @@ func file_app_observatory_multiObservatory_config_proto_init() { out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_app_observatory_multiObservatory_config_proto_rawDesc, + RawDescriptor: file_app_observatory_multiobservatory_config_proto_rawDesc, NumEnums: 0, NumMessages: 1, NumExtensions: 0, NumServices: 0, }, - GoTypes: file_app_observatory_multiObservatory_config_proto_goTypes, - DependencyIndexes: file_app_observatory_multiObservatory_config_proto_depIdxs, - MessageInfos: file_app_observatory_multiObservatory_config_proto_msgTypes, + GoTypes: file_app_observatory_multiobservatory_config_proto_goTypes, + DependencyIndexes: file_app_observatory_multiobservatory_config_proto_depIdxs, + MessageInfos: file_app_observatory_multiobservatory_config_proto_msgTypes, }.Build() - File_app_observatory_multiObservatory_config_proto = out.File - file_app_observatory_multiObservatory_config_proto_rawDesc = nil - file_app_observatory_multiObservatory_config_proto_goTypes = nil - file_app_observatory_multiObservatory_config_proto_depIdxs = nil + File_app_observatory_multiobservatory_config_proto = out.File + file_app_observatory_multiobservatory_config_proto_rawDesc = nil + file_app_observatory_multiobservatory_config_proto_goTypes = nil + file_app_observatory_multiobservatory_config_proto_depIdxs = nil } diff --git a/app/observatory/multiObservatory/config.proto b/app/observatory/multiobservatory/config.proto similarity index 85% rename from app/observatory/multiObservatory/config.proto rename to app/observatory/multiobservatory/config.proto index 3ac3906fb..d1a983365 100644 --- a/app/observatory/multiObservatory/config.proto +++ b/app/observatory/multiobservatory/config.proto @@ -1,8 +1,8 @@ syntax = "proto3"; -package v2ray.core.app.observatory.multiObservatory; +package v2ray.core.app.observatory.multiobservatory; option csharp_namespace = "V2Ray.Core.App.Observatory.MultiObservatory"; -option go_package = "github.com/v2fly/v2ray-core/v4/app/observatory/multiObservatory"; +option go_package = "github.com/v2fly/v2ray-core/v4/app/observatory/multiobservatory"; option java_package = "com.v2ray.core.app.observatory.multiObservatory"; option java_multiple_files = true; @@ -11,7 +11,7 @@ import "common/protoext/extensions.proto"; message Config{ option (v2ray.core.common.protoext.message_opt).type = "service"; - option (v2ray.core.common.protoext.message_opt).short_name = "multiObservatory"; + option (v2ray.core.common.protoext.message_opt).short_name = "multiobservatory"; v2ray.core.common.taggedfeatures.Config holders = 1 ; -} \ No newline at end of file +} diff --git a/app/observatory/multiObservatory/muti.go b/app/observatory/multiobservatory/multi.go similarity index 93% rename from app/observatory/multiObservatory/muti.go rename to app/observatory/multiobservatory/multi.go index fcca37937..aa1f7a5d0 100644 --- a/app/observatory/multiObservatory/muti.go +++ b/app/observatory/multiobservatory/multi.go @@ -1,4 +1,4 @@ -package multiObservatory +package multiobservatory import ( "context" @@ -36,7 +36,7 @@ func New(ctx context.Context, config *Config) (*Observer, error) { func (x *Config) UnmarshalJSONPB(unmarshaler *jsonpb.Unmarshaler, bytes []byte) error { var err error - x.Holders, err = taggedfeatures.LoadJsonConfig(context.TODO(), "service", "background", bytes) + x.Holders, err = taggedfeatures.LoadJSONConfig(context.TODO(), "service", "background", bytes) return err } diff --git a/app/restful-api/config.pb.go b/app/restful-api/config.pb.go deleted file mode 100644 index 8157b8567..000000000 --- a/app/restful-api/config.pb.go +++ /dev/null @@ -1,175 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.27.1 -// protoc v3.17.3 -// source: app/restful-api/config.proto - -package restful_api - -import ( - _ "github.com/v2fly/v2ray-core/v4/common/protoext" - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -type Config struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - ListenAddr string `protobuf:"bytes,1,opt,name=listen_addr,json=listenAddr,proto3" json:"listen_addr,omitempty"` - ListenPort int32 `protobuf:"varint,2,opt,name=listen_port,json=listenPort,proto3" json:"listen_port,omitempty"` - AuthToken string `protobuf:"bytes,3,opt,name=auth_token,json=authToken,proto3" json:"auth_token,omitempty"` -} - -func (x *Config) Reset() { - *x = Config{} - if protoimpl.UnsafeEnabled { - mi := &file_app_restful_api_config_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Config) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Config) ProtoMessage() {} - -func (x *Config) ProtoReflect() protoreflect.Message { - mi := &file_app_restful_api_config_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Config.ProtoReflect.Descriptor instead. -func (*Config) Descriptor() ([]byte, []int) { - return file_app_restful_api_config_proto_rawDescGZIP(), []int{0} -} - -func (x *Config) GetListenAddr() string { - if x != nil { - return x.ListenAddr - } - return "" -} - -func (x *Config) GetListenPort() int32 { - if x != nil { - return x.ListenPort - } - return 0 -} - -func (x *Config) GetAuthToken() string { - if x != nil { - return x.AuthToken - } - return "" -} - -var File_app_restful_api_config_proto protoreflect.FileDescriptor - -var file_app_restful_api_config_proto_rawDesc = []byte{ - 0x0a, 0x1c, 0x61, 0x70, 0x70, 0x2f, 0x72, 0x65, 0x73, 0x74, 0x66, 0x75, 0x6c, 0x2d, 0x61, 0x70, - 0x69, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x14, - 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x72, 0x65, 0x73, 0x74, 0x66, 0x75, - 0x6c, 0x61, 0x70, 0x69, 0x1a, 0x20, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x65, 0x78, 0x74, 0x2f, 0x65, 0x78, 0x74, 0x65, 0x6e, 0x73, 0x69, 0x6f, 0x6e, 0x73, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x89, 0x01, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x66, 0x69, - 0x67, 0x12, 0x1f, 0x0a, 0x0b, 0x6c, 0x69, 0x73, 0x74, 0x65, 0x6e, 0x5f, 0x61, 0x64, 0x64, 0x72, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6c, 0x69, 0x73, 0x74, 0x65, 0x6e, 0x41, 0x64, - 0x64, 0x72, 0x12, 0x1f, 0x0a, 0x0b, 0x6c, 0x69, 0x73, 0x74, 0x65, 0x6e, 0x5f, 0x70, 0x6f, 0x72, - 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, 0x6c, 0x69, 0x73, 0x74, 0x65, 0x6e, 0x50, - 0x6f, 0x72, 0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x61, 0x75, 0x74, 0x68, 0x5f, 0x74, 0x6f, 0x6b, 0x65, - 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x61, 0x75, 0x74, 0x68, 0x54, 0x6f, 0x6b, - 0x65, 0x6e, 0x3a, 0x1e, 0x82, 0xb5, 0x18, 0x09, 0x0a, 0x07, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, - 0x65, 0x82, 0xb5, 0x18, 0x0d, 0x12, 0x0b, 0x72, 0x65, 0x73, 0x74, 0x66, 0x75, 0x6c, 0x2d, 0x61, - 0x70, 0x69, 0x42, 0x6e, 0x0a, 0x1a, 0x63, 0x6f, 0x6d, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, - 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x72, 0x65, 0x73, 0x74, 0x61, 0x70, 0x69, - 0x50, 0x01, 0x5a, 0x3a, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x76, - 0x32, 0x66, 0x6c, 0x79, 0x2f, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2d, 0x63, 0x6f, 0x72, 0x65, 0x2f, - 0x76, 0x34, 0x2f, 0x61, 0x70, 0x70, 0x2f, 0x72, 0x65, 0x73, 0x74, 0x66, 0x75, 0x6c, 0x2d, 0x61, - 0x70, 0x69, 0x3b, 0x72, 0x65, 0x73, 0x74, 0x66, 0x75, 0x6c, 0x5f, 0x61, 0x70, 0x69, 0xaa, 0x02, - 0x11, 0x56, 0x32, 0x52, 0x61, 0x79, 0x2e, 0x41, 0x70, 0x70, 0x2e, 0x52, 0x65, 0x73, 0x74, 0x61, - 0x70, 0x69, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_app_restful_api_config_proto_rawDescOnce sync.Once - file_app_restful_api_config_proto_rawDescData = file_app_restful_api_config_proto_rawDesc -) - -func file_app_restful_api_config_proto_rawDescGZIP() []byte { - file_app_restful_api_config_proto_rawDescOnce.Do(func() { - file_app_restful_api_config_proto_rawDescData = protoimpl.X.CompressGZIP(file_app_restful_api_config_proto_rawDescData) - }) - return file_app_restful_api_config_proto_rawDescData -} - -var file_app_restful_api_config_proto_msgTypes = make([]protoimpl.MessageInfo, 1) -var file_app_restful_api_config_proto_goTypes = []interface{}{ - (*Config)(nil), // 0: v2ray.app.restfulapi.Config -} -var file_app_restful_api_config_proto_depIdxs = []int32{ - 0, // [0:0] is the sub-list for method output_type - 0, // [0:0] is the sub-list for method input_type - 0, // [0:0] is the sub-list for extension type_name - 0, // [0:0] is the sub-list for extension extendee - 0, // [0:0] is the sub-list for field type_name -} - -func init() { file_app_restful_api_config_proto_init() } -func file_app_restful_api_config_proto_init() { - if File_app_restful_api_config_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_app_restful_api_config_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Config); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_app_restful_api_config_proto_rawDesc, - NumEnums: 0, - NumMessages: 1, - NumExtensions: 0, - NumServices: 0, - }, - GoTypes: file_app_restful_api_config_proto_goTypes, - DependencyIndexes: file_app_restful_api_config_proto_depIdxs, - MessageInfos: file_app_restful_api_config_proto_msgTypes, - }.Build() - File_app_restful_api_config_proto = out.File - file_app_restful_api_config_proto_rawDesc = nil - file_app_restful_api_config_proto_goTypes = nil - file_app_restful_api_config_proto_depIdxs = nil -} diff --git a/app/restful-api/config.go b/app/restfulapi/config.go similarity index 92% rename from app/restful-api/config.go rename to app/restfulapi/config.go index eb089ba1c..fef0ee960 100644 --- a/app/restful-api/config.go +++ b/app/restfulapi/config.go @@ -1,4 +1,4 @@ -package restful_api +package restfulapi import ( "context" diff --git a/app/restfulapi/config.pb.go b/app/restfulapi/config.pb.go new file mode 100644 index 000000000..67c5e027d --- /dev/null +++ b/app/restfulapi/config.pb.go @@ -0,0 +1,174 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.27.1 +// protoc v3.17.3 +// source: app/restfulapi/config.proto + +package restfulapi + +import ( + _ "github.com/v2fly/v2ray-core/v4/common/protoext" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type Config struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + ListenAddr string `protobuf:"bytes,1,opt,name=listen_addr,json=listenAddr,proto3" json:"listen_addr,omitempty"` + ListenPort int32 `protobuf:"varint,2,opt,name=listen_port,json=listenPort,proto3" json:"listen_port,omitempty"` + AuthToken string `protobuf:"bytes,3,opt,name=auth_token,json=authToken,proto3" json:"auth_token,omitempty"` +} + +func (x *Config) Reset() { + *x = Config{} + if protoimpl.UnsafeEnabled { + mi := &file_app_restfulapi_config_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Config) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Config) ProtoMessage() {} + +func (x *Config) ProtoReflect() protoreflect.Message { + mi := &file_app_restfulapi_config_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Config.ProtoReflect.Descriptor instead. +func (*Config) Descriptor() ([]byte, []int) { + return file_app_restfulapi_config_proto_rawDescGZIP(), []int{0} +} + +func (x *Config) GetListenAddr() string { + if x != nil { + return x.ListenAddr + } + return "" +} + +func (x *Config) GetListenPort() int32 { + if x != nil { + return x.ListenPort + } + return 0 +} + +func (x *Config) GetAuthToken() string { + if x != nil { + return x.AuthToken + } + return "" +} + +var File_app_restfulapi_config_proto protoreflect.FileDescriptor + +var file_app_restfulapi_config_proto_rawDesc = []byte{ + 0x0a, 0x1b, 0x61, 0x70, 0x70, 0x2f, 0x72, 0x65, 0x73, 0x74, 0x66, 0x75, 0x6c, 0x61, 0x70, 0x69, + 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x14, 0x76, + 0x32, 0x72, 0x61, 0x79, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x72, 0x65, 0x73, 0x74, 0x66, 0x75, 0x6c, + 0x61, 0x70, 0x69, 0x1a, 0x20, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x65, 0x78, 0x74, 0x2f, 0x65, 0x78, 0x74, 0x65, 0x6e, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x88, 0x01, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, + 0x12, 0x1f, 0x0a, 0x0b, 0x6c, 0x69, 0x73, 0x74, 0x65, 0x6e, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6c, 0x69, 0x73, 0x74, 0x65, 0x6e, 0x41, 0x64, 0x64, + 0x72, 0x12, 0x1f, 0x0a, 0x0b, 0x6c, 0x69, 0x73, 0x74, 0x65, 0x6e, 0x5f, 0x70, 0x6f, 0x72, 0x74, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, 0x6c, 0x69, 0x73, 0x74, 0x65, 0x6e, 0x50, 0x6f, + 0x72, 0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x61, 0x75, 0x74, 0x68, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x61, 0x75, 0x74, 0x68, 0x54, 0x6f, 0x6b, 0x65, + 0x6e, 0x3a, 0x1d, 0x82, 0xb5, 0x18, 0x09, 0x0a, 0x07, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, + 0x82, 0xb5, 0x18, 0x0c, 0x12, 0x0a, 0x72, 0x65, 0x73, 0x74, 0x66, 0x75, 0x6c, 0x61, 0x70, 0x69, + 0x42, 0x61, 0x0a, 0x1a, 0x63, 0x6f, 0x6d, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, + 0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x72, 0x65, 0x73, 0x74, 0x61, 0x70, 0x69, 0x50, 0x01, + 0x5a, 0x2d, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x76, 0x32, 0x66, + 0x6c, 0x79, 0x2f, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2d, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x76, 0x34, + 0x2f, 0x61, 0x70, 0x70, 0x2f, 0x72, 0x65, 0x73, 0x74, 0x66, 0x75, 0x6c, 0x61, 0x70, 0x69, 0xaa, + 0x02, 0x11, 0x56, 0x32, 0x52, 0x61, 0x79, 0x2e, 0x41, 0x70, 0x70, 0x2e, 0x52, 0x65, 0x73, 0x74, + 0x61, 0x70, 0x69, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_app_restfulapi_config_proto_rawDescOnce sync.Once + file_app_restfulapi_config_proto_rawDescData = file_app_restfulapi_config_proto_rawDesc +) + +func file_app_restfulapi_config_proto_rawDescGZIP() []byte { + file_app_restfulapi_config_proto_rawDescOnce.Do(func() { + file_app_restfulapi_config_proto_rawDescData = protoimpl.X.CompressGZIP(file_app_restfulapi_config_proto_rawDescData) + }) + return file_app_restfulapi_config_proto_rawDescData +} + +var file_app_restfulapi_config_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_app_restfulapi_config_proto_goTypes = []interface{}{ + (*Config)(nil), // 0: v2ray.app.restfulapi.Config +} +var file_app_restfulapi_config_proto_depIdxs = []int32{ + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_app_restfulapi_config_proto_init() } +func file_app_restfulapi_config_proto_init() { + if File_app_restfulapi_config_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_app_restfulapi_config_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Config); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_app_restfulapi_config_proto_rawDesc, + NumEnums: 0, + NumMessages: 1, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_app_restfulapi_config_proto_goTypes, + DependencyIndexes: file_app_restfulapi_config_proto_depIdxs, + MessageInfos: file_app_restfulapi_config_proto_msgTypes, + }.Build() + File_app_restfulapi_config_proto = out.File + file_app_restfulapi_config_proto_rawDesc = nil + file_app_restfulapi_config_proto_goTypes = nil + file_app_restfulapi_config_proto_depIdxs = nil +} diff --git a/app/restful-api/config.proto b/app/restfulapi/config.proto similarity index 82% rename from app/restful-api/config.proto rename to app/restfulapi/config.proto index 6d646ea7a..9d5def4a9 100644 --- a/app/restful-api/config.proto +++ b/app/restfulapi/config.proto @@ -2,7 +2,7 @@ syntax = "proto3"; package v2ray.app.restfulapi; option csharp_namespace = "V2Ray.App.Restapi"; -option go_package = "github.com/v2fly/v2ray-core/v4/app/restful-api;restful_api"; +option go_package = "github.com/v2fly/v2ray-core/v4/app/restfulapi"; option java_package = "com.v2ray.core.app.restapi"; option java_multiple_files = true; @@ -10,9 +10,9 @@ import "common/protoext/extensions.proto"; message Config{ option (v2ray.core.common.protoext.message_opt).type = "service"; - option (v2ray.core.common.protoext.message_opt).short_name = "restful-api"; + option (v2ray.core.common.protoext.message_opt).short_name = "restfulapi"; string listen_addr = 1; int32 listen_port = 2; string auth_token = 3; -} \ No newline at end of file +} diff --git a/app/restful-api/errors.generated.go b/app/restfulapi/errors.generated.go similarity index 91% rename from app/restful-api/errors.generated.go rename to app/restfulapi/errors.generated.go index f0902c1fd..34f32d6cb 100644 --- a/app/restful-api/errors.generated.go +++ b/app/restfulapi/errors.generated.go @@ -1,4 +1,4 @@ -package restful_api +package restfulapi import "github.com/v2fly/v2ray-core/v4/common/errors" diff --git a/app/restful-api/restful-api.go b/app/restfulapi/restful_api.go similarity index 99% rename from app/restful-api/restful-api.go rename to app/restfulapi/restful_api.go index afcdb5457..9e1bb1e7b 100644 --- a/app/restful-api/restful-api.go +++ b/app/restfulapi/restful_api.go @@ -1,4 +1,4 @@ -package restful_api +package restfulapi import ( "net/http" diff --git a/app/restful-api/service.go b/app/restfulapi/service.go similarity index 98% rename from app/restful-api/service.go rename to app/restfulapi/service.go index 9b0fc6683..4c4234599 100644 --- a/app/restful-api/service.go +++ b/app/restfulapi/service.go @@ -1,4 +1,4 @@ -package restful_api +package restfulapi import ( "context" diff --git a/app/restful-api/service_test.go b/app/restfulapi/service_test.go similarity index 93% rename from app/restful-api/service_test.go rename to app/restfulapi/service_test.go index 850d918e7..840b1c314 100644 --- a/app/restful-api/service_test.go +++ b/app/restfulapi/service_test.go @@ -1,4 +1,4 @@ -package restful_api +package restfulapi import ( "reflect" diff --git a/app/router/config.go b/app/router/config.go index 908c6eff4..c201f469d 100644 --- a/app/router/config.go +++ b/app/router/config.go @@ -178,7 +178,7 @@ func (br *BalancingRule) UnmarshalJSONPB(unmarshaler *jsonpb.Unmarshaler, bytes if stub.Strategy == "" { stub.Strategy = "random" } - settingsPack, err := v5cfg.LoadHeterogeneousConfigFromRawJson(context.TODO(), "balancer", stub.Strategy, stub.StrategySettings) + settingsPack, err := v5cfg.LoadHeterogeneousConfigFromRawJSON(context.TODO(), "balancer", stub.Strategy, stub.StrategySettings) if err != nil { return err } diff --git a/app/router/router.go b/app/router/router.go index 8073c2440..85aab1571 100644 --- a/app/router/router.go +++ b/app/router/router.go @@ -173,7 +173,6 @@ func init() { var routingRules []*RoutingRule for _, v := range simplifiedConfig.Rule { - rule := new(RoutingRule) for _, geo := range v.Geoip { diff --git a/app/router/strategy_leastload.go b/app/router/strategy_leastload.go index 4b33c0392..fe34557cc 100644 --- a/app/router/strategy_leastload.go +++ b/app/router/strategy_leastload.go @@ -64,8 +64,8 @@ func (l *LeastLoadStrategy) InjectContext(ctx context.Context) { l.ctx = ctx } -func (s *LeastLoadStrategy) PickOutbound(candidates []string) string { - selects := s.pickOutbounds(candidates) +func (l *LeastLoadStrategy) PickOutbound(candidates []string) string { + selects := l.pickOutbounds(candidates) count := len(selects) if count == 0 { // goes to fallbackTag @@ -74,9 +74,9 @@ func (s *LeastLoadStrategy) PickOutbound(candidates []string) string { return selects[dice.Roll(count)].Tag } -func (s *LeastLoadStrategy) pickOutbounds(candidates []string) []*node { - qualified := s.getNodes(candidates, time.Duration(s.settings.MaxRTT)) - selects := s.selectLeastLoad(qualified) +func (l *LeastLoadStrategy) pickOutbounds(candidates []string) []*node { + qualified := l.getNodes(candidates, time.Duration(l.settings.MaxRTT)) + selects := l.selectLeastLoad(qualified) return selects } @@ -96,12 +96,12 @@ func (s *LeastLoadStrategy) pickOutbounds(candidates []string) []*node { // 3. Speed priority: Baselines + `Expected Count <= 0`. // go through all baselines until find selects, if not, select none. Used in combination // with 'balancer.fallbackTag', it means: selects qualified nodes or use the fallback. -func (s *LeastLoadStrategy) selectLeastLoad(nodes []*node) []*node { +func (l *LeastLoadStrategy) selectLeastLoad(nodes []*node) []*node { if len(nodes) == 0 { newError("least load: no qualified outbound").AtInfo().WriteToLog() return nil } - expected := int(s.settings.Expected) + expected := int(l.settings.Expected) availableCount := len(nodes) if expected > availableCount { return nodes @@ -110,13 +110,13 @@ func (s *LeastLoadStrategy) selectLeastLoad(nodes []*node) []*node { if expected <= 0 { expected = 1 } - if len(s.settings.Baselines) == 0 { + if len(l.settings.Baselines) == 0 { return nodes[:expected] } count := 0 // go through all base line until find expected selects - for _, b := range s.settings.Baselines { + for _, b := range l.settings.Baselines { baseline := time.Duration(b) for i := 0; i < availableCount; i++ { if nodes[i].RTTDeviationCost > baseline { @@ -130,30 +130,30 @@ func (s *LeastLoadStrategy) selectLeastLoad(nodes []*node) []*node { break } } - if s.settings.Expected > 0 && count < expected { + if l.settings.Expected > 0 && count < expected { count = expected } return nodes[:count] } -func (s *LeastLoadStrategy) getNodes(candidates []string, maxRTT time.Duration) []*node { - if s.observer == nil { - common.Must(core.RequireFeatures(s.ctx, func(observatory extension.Observatory) error { - s.observer = observatory +func (l *LeastLoadStrategy) getNodes(candidates []string, maxRTT time.Duration) []*node { + if l.observer == nil { + common.Must(core.RequireFeatures(l.ctx, func(observatory extension.Observatory) error { + l.observer = observatory return nil })) } var result proto.Message - if s.settings.ObserverTag == "" { - observeResult, err := s.observer.GetObservation(s.ctx) + if l.settings.ObserverTag == "" { + observeResult, err := l.observer.GetObservation(l.ctx) if err != nil { newError("cannot get observation").Base(err).WriteToLog() return make([]*node, 0) } result = observeResult } else { - observeResult, err := common.Must2(s.observer.(features.TaggedFeatures).GetFeaturesByTag(s.settings.ObserverTag)).(extension.Observatory).GetObservation(s.ctx) + observeResult, err := common.Must2(l.observer.(features.TaggedFeatures).GetFeaturesByTag(l.settings.ObserverTag)).(extension.Observatory).GetObservation(l.ctx) if err != nil { newError("cannot get observation").Base(err).WriteToLog() return make([]*node, 0) @@ -175,16 +175,15 @@ func (s *LeastLoadStrategy) getNodes(candidates []string, maxRTT time.Duration) CountFail: 1, RTTAverage: time.Duration(v.Delay) * time.Millisecond, RTTDeviation: time.Duration(v.Delay) * time.Millisecond, - RTTDeviationCost: time.Duration(s.costs.Apply(v.OutboundTag, float64(time.Duration(v.Delay)*time.Millisecond))), + RTTDeviationCost: time.Duration(l.costs.Apply(v.OutboundTag, float64(time.Duration(v.Delay)*time.Millisecond))), } if v.HealthPing != nil { record.RTTAverage = time.Duration(v.HealthPing.Average) record.RTTDeviation = time.Duration(v.HealthPing.Deviation) - record.RTTDeviationCost = time.Duration(s.costs.Apply(v.OutboundTag, float64(v.HealthPing.Deviation))) + record.RTTDeviationCost = time.Duration(l.costs.Apply(v.OutboundTag, float64(v.HealthPing.Deviation))) record.CountAll = int(v.HealthPing.All) record.CountFail = int(v.HealthPing.Fail) - } ret = append(ret, record) } diff --git a/common/cmdarg/arg.go b/common/cmdarg/arg.go index 7c5ccc985..4b448651a 100644 --- a/common/cmdarg/arg.go +++ b/common/cmdarg/arg.go @@ -24,10 +24,7 @@ func LoadArg(arg string) (out io.Reader, err error) { // LoadArgToBytes loads one arg to []byte, maybe an remote url, or local file path func LoadArgToBytes(arg string) (out []byte, err error) { - switch { - default: - out, err = ioutil.ReadFile(arg) - } + out, err = ioutil.ReadFile(arg) if err != nil { return } diff --git a/common/environment/envctx/env.go b/common/environment/envctx/env.go index c95181e80..c9aa5ac41 100644 --- a/common/environment/envctx/env.go +++ b/common/environment/envctx/env.go @@ -13,8 +13,5 @@ func ContextWithEnvironment(ctx context.Context, environment interface{}) contex } func EnvironmentFromContext(ctx context.Context) interface{} { - if environment, ok := ctx.Value(environmentKey).(interface{}); ok { - return environment - } - return nil + return ctx.Value(environmentKey) } diff --git a/common/net/network.go b/common/net/network.go index c9c37d1c1..407252f17 100644 --- a/common/net/network.go +++ b/common/net/network.go @@ -41,7 +41,7 @@ func ParseNetwork(net string) Network { } func ParseNetworks(netlist string) []Network { - strlist := strings.Split(string(netlist), ",") + strlist := strings.Split(netlist, ",") nl := make([]Network, len(strlist)) for idx, network := range strlist { nl[idx] = ParseNetwork(network) diff --git a/common/protoext/extensions.go b/common/protoext/extensions.go index 9a5359408..bf8006583 100644 --- a/common/protoext/extensions.go +++ b/common/protoext/extensions.go @@ -10,22 +10,18 @@ import ( func GetMessageOptions(msgDesc protoreflect.MessageDescriptor) (*MessageOpt, error) { msgOpt := msgDesc.Options().(*descriptorpb.MessageOptions) - var V2MessageOption *MessageOpt - if msgOptRet, err := proto.GetExtension(msgOpt, E_MessageOpt); err != nil { + msgOptRet, err := proto.GetExtension(msgOpt, E_MessageOpt) + if err != nil { return nil, newError("unable to parse extension from message").Base(err) - } else { - V2MessageOption = msgOptRet.(*MessageOpt) } - return V2MessageOption, nil + return msgOptRet.(*MessageOpt), nil } func GetFieldOptions(fieldDesc protoreflect.FieldDescriptor) (*FieldOpt, error) { fieldOpt := fieldDesc.Options().(*descriptorpb.FieldOptions) - var V2FieldOption *FieldOpt - if msgOptRet, err := proto.GetExtension(fieldOpt, E_FieldOpt); err != nil { + msgOptRet, err := proto.GetExtension(fieldOpt, E_FieldOpt) + if err != nil { return nil, newError("unable to parse extension from message").Base(err) - } else { - V2FieldOption = msgOptRet.(*FieldOpt) } - return V2FieldOption, nil + return msgOptRet.(*FieldOpt), nil } diff --git a/common/protofilter/filter.go b/common/protofilter/filter.go index b834791b9..2195ff3f9 100644 --- a/common/protofilter/filter.go +++ b/common/protofilter/filter.go @@ -53,8 +53,7 @@ func filterMessage(ctx context.Context, message protoreflect.Message) error { } if v2extension.ConvertTimeParseIp != "" { - strIp := value.String() - ipValue := net.ParseIP(strIp) + ipValue := net.ParseIP(value.String()) target := message.Descriptor().Fields().ByTextName(v2extension.ConvertTimeParseIp) pendingWriteQueue = append(pendingWriteQueue, pendingWrite{ field: target, @@ -116,10 +115,7 @@ func filterMap(ctx context.Context, mapValue protoreflect.Map) error { var err error mapValue.Range(func(key protoreflect.MapKey, value protoreflect.Value) bool { err = filterMessage(ctx, value.Message()) - if err != nil { - return false - } - return true + return err == nil }) return err } diff --git a/common/session/context.go b/common/session/context.go index 2e43b9205..01b17e1eb 100644 --- a/common/session/context.go +++ b/common/session/context.go @@ -14,7 +14,7 @@ const ( muxPreferedSessionKey sockoptSessionKey trackedConnectionErrorKey - handlerSessionKey + handlerSessionKey // nolint: varcheck ) // ContextWithID returns a new context with the given ID. diff --git a/common/taggedfeatures/configloader.go b/common/taggedfeatures/configloader.go index dc2f844ae..78bb0a217 100644 --- a/common/taggedfeatures/configloader.go +++ b/common/taggedfeatures/configloader.go @@ -10,7 +10,7 @@ import ( "github.com/v2fly/v2ray-core/v4/infra/conf/v5cfg" ) -func LoadJsonConfig(ctx context.Context, interfaceType, defaultImpl string, message json.RawMessage) (*Config, error) { +func LoadJSONConfig(ctx context.Context, interfaceType, defaultImpl string, message json.RawMessage) (*Config, error) { type ItemStub struct { MemberType string `json:"type"` Tag string `json:"tag"` @@ -27,7 +27,7 @@ func LoadJsonConfig(ctx context.Context, interfaceType, defaultImpl string, mess if v.MemberType == "" { v.MemberType = defaultImpl } - pack, err := v5cfg.LoadHeterogeneousConfigFromRawJson(ctx, interfaceType, v.MemberType, v.Value) + pack, err := v5cfg.LoadHeterogeneousConfigFromRawJSON(ctx, interfaceType, v.MemberType, v.Value) if err != nil { return nil, err } diff --git a/config.go b/config.go index d912c9bfd..74bd80972 100644 --- a/config.go +++ b/config.go @@ -154,9 +154,8 @@ func loadSingleConfigAutoFormat(input interface{}) (*Config, error) { c, err := f.Loader(input) if err == nil { return c, nil - } else { - errorReasons.WriteString(fmt.Sprintf("unable to parse as %v:%v;", f.Name[0], err.Error())) } + errorReasons.WriteString(fmt.Sprintf("unable to parse as %v:%v;", f.Name[0], err.Error())) } return nil, newError("tried all loaders but failed when attempting to parse: ", input, ";", errorReasons.String()).AtWarning() } diff --git a/infra/conf/json/toml.go b/infra/conf/json/toml.go index ca5c67241..6d784529c 100644 --- a/infra/conf/json/toml.go +++ b/infra/conf/json/toml.go @@ -32,5 +32,5 @@ func mapToJSON(tree *toml.Tree) (string, error) { if err != nil { return "", err } - return string(bytes[:]), nil + return string(bytes), nil } diff --git a/infra/conf/jsonpb/jsonpb.go b/infra/conf/jsonpb/jsonpb.go index c10ee3571..d7ca651d8 100644 --- a/infra/conf/jsonpb/jsonpb.go +++ b/infra/conf/jsonpb/jsonpb.go @@ -16,7 +16,7 @@ import ( //go:generate go run github.com/v2fly/v2ray-core/v4/common/errors/errorgen -func loadJsonPb(data io.Reader) (*core.Config, error) { +func loadJSONPB(data io.Reader) (*core.Config, error) { coreconf := &core.Config{} jsonpbloader := &jsonpb.Unmarshaler{AnyResolver: serial.GetResolver()} err := jsonpbloader.Unmarshal(data, coreconf) @@ -26,7 +26,7 @@ func loadJsonPb(data io.Reader) (*core.Config, error) { return coreconf, nil } -func dumpJsonPb(config proto.Message, w io.Writer) error { +func dumpJSONPb(config proto.Message, w io.Writer) error { jsonpbdumper := &jsonpb.Marshaler{AnyResolver: serial.GetResolver()} err := jsonpbdumper.Marshal(w, config) if err != nil { @@ -35,8 +35,8 @@ func dumpJsonPb(config proto.Message, w io.Writer) error { return nil } -func DumpJsonPb(config proto.Message, w io.Writer) error { - return dumpJsonPb(config, w) +func DumpJSONPb(config proto.Message, w io.Writer) error { + return dumpJSONPb(config, w) } const FormatProtobufJSONPB = "jsonpb" @@ -56,13 +56,13 @@ func init() { if err != nil { return nil, err } - return loadJsonPb(bytes.NewReader(data)) + return loadJSONPB(bytes.NewReader(data)) case io.Reader: data, err := buf.ReadAllToBytes(v) if err != nil { return nil, err } - return loadJsonPb(bytes.NewReader(data)) + return loadJSONPB(bytes.NewReader(data)) default: return nil, newError("unknow type") } diff --git a/infra/conf/serial/loader.go b/infra/conf/serial/loader.go index f36541514..d51a6be74 100644 --- a/infra/conf/serial/loader.go +++ b/infra/conf/serial/loader.go @@ -8,7 +8,7 @@ import ( core "github.com/v2fly/v2ray-core/v4" "github.com/v2fly/v2ray-core/v4/common/errors" json_reader "github.com/v2fly/v2ray-core/v4/infra/conf/json" - "github.com/v2fly/v2ray-core/v4/infra/conf/v4" + v4 "github.com/v2fly/v2ray-core/v4/infra/conf/v4" ) type offset struct { diff --git a/infra/conf/synthetic/dns/dns.go b/infra/conf/synthetic/dns/dns.go index d685bc70d..44691e9bd 100644 --- a/infra/conf/synthetic/dns/dns.go +++ b/infra/conf/synthetic/dns/dns.go @@ -139,7 +139,7 @@ var typeMap = map[routercommon.Domain_Type]dns.DomainMatchingType{ } // DNSConfig is a JSON serializable object for dns.Config. -type DNSConfig struct { +type DNSConfig struct { // nolint: revive Servers []*NameServerConfig `json:"servers"` Hosts map[string]*HostAddress `json:"hosts"` ClientIP *cfgcommon.Address `json:"clientIp"` @@ -216,7 +216,6 @@ func (c *DNSConfig) Build() (*dns.Config, error) { } else { return nil, newError("unable to create geo data loader ").Base(err) } - } cfgEnv := cfgcommon.GetConfigureLoadingEnvironment(c.cfgctx) diff --git a/infra/conf/synthetic/log/log.go b/infra/conf/synthetic/log/log.go index d4d1b2bfe..3786c115b 100644 --- a/infra/conf/synthetic/log/log.go +++ b/infra/conf/synthetic/log/log.go @@ -14,7 +14,7 @@ func DefaultLogConfig() *log.Config { } } -type LogConfig struct { +type LogConfig struct { // nolint: revive AccessLog string `json:"access"` ErrorLog string `json:"error"` LogLevel string `json:"loglevel"` diff --git a/infra/conf/synthetic/router/router.go b/infra/conf/synthetic/router/router.go index c830b0dfc..31ae3080d 100644 --- a/infra/conf/synthetic/router/router.go +++ b/infra/conf/synthetic/router/router.go @@ -17,7 +17,7 @@ import ( rule2 "github.com/v2fly/v2ray-core/v4/infra/conf/rule" ) -type RouterRulesConfig struct { +type RouterRulesConfig struct { // nolint: revive RuleList []json.RawMessage `json:"rules"` DomainStrategy string `json:"domainStrategy"` } @@ -82,7 +82,7 @@ func (r *BalancingRule) Build() (*router.BalancingRule, error) { }, nil } -type RouterConfig struct { +type RouterConfig struct { // nolint: revive Settings *RouterRulesConfig `json:"settings"` // Deprecated RuleList []json.RawMessage `json:"rules"` DomainStrategy *string `json:"domainStrategy"` diff --git a/infra/conf/v2jsonpb/follower.go b/infra/conf/v2jsonpb/follower.go index 86e4d2920..4def263c3 100644 --- a/infra/conf/v2jsonpb/follower.go +++ b/infra/conf/v2jsonpb/follower.go @@ -89,18 +89,18 @@ func (v *V2JsonProtobufFollower) Clear(descriptor protoreflect.FieldDescriptor) } func (v *V2JsonProtobufFollower) Set(descriptor protoreflect.FieldDescriptor, value protoreflect.Value) { - switch descriptor.(type) { + switch descriptor := descriptor.(type) { case V2JsonProtobufFollowerFieldDescriptor: - v.Message.Set(descriptor.(V2JsonProtobufFollowerFieldDescriptor).FieldDescriptor, value) + v.Message.Set(descriptor.FieldDescriptor, value) case *V2JsonProtobufFollowerFieldDescriptor: - v.Message.Set(descriptor.(*V2JsonProtobufFollowerFieldDescriptor).FieldDescriptor, value) + v.Message.Set(descriptor.FieldDescriptor, value) case *V2JsonProtobufAnyValueField: protodata := value.Message() bytesw, err := proto.MarshalOptions{AllowPartial: true}.Marshal(&V2JsonProtobufAnyValueFieldReturn{protodata}) if err != nil { panic(err) } - v.Message.Set(descriptor.(*V2JsonProtobufAnyValueField).FieldDescriptor, protoreflect.ValueOfBytes(bytesw)) + v.Message.Set(descriptor.FieldDescriptor, protoreflect.ValueOfBytes(bytesw)) default: v.Message.Set(descriptor, value) } @@ -122,9 +122,7 @@ 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() - v2type := serial.V2TypeFromURL(url) instance, err := serial.GetInstance(v2type) if err != nil { diff --git a/infra/conf/v4/blackhole_test.go b/infra/conf/v4/blackhole_test.go index 9d3f7c9b3..c8f8561d9 100644 --- a/infra/conf/v4/blackhole_test.go +++ b/infra/conf/v4/blackhole_test.go @@ -6,7 +6,7 @@ import ( "github.com/v2fly/v2ray-core/v4/common/serial" "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/testassist" - "github.com/v2fly/v2ray-core/v4/infra/conf/v4" + v4 "github.com/v2fly/v2ray-core/v4/infra/conf/v4" "github.com/v2fly/v2ray-core/v4/proxy/blackhole" ) diff --git a/infra/conf/v4/dns_proxy_test.go b/infra/conf/v4/dns_proxy_test.go index f99cf9583..7af88d493 100644 --- a/infra/conf/v4/dns_proxy_test.go +++ b/infra/conf/v4/dns_proxy_test.go @@ -6,7 +6,7 @@ import ( "github.com/v2fly/v2ray-core/v4/common/net" "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/testassist" - "github.com/v2fly/v2ray-core/v4/infra/conf/v4" + v4 "github.com/v2fly/v2ray-core/v4/infra/conf/v4" "github.com/v2fly/v2ray-core/v4/proxy/dns" ) diff --git a/infra/conf/v4/dokodemo_test.go b/infra/conf/v4/dokodemo_test.go index ce2298138..5670f80e3 100644 --- a/infra/conf/v4/dokodemo_test.go +++ b/infra/conf/v4/dokodemo_test.go @@ -6,7 +6,7 @@ import ( "github.com/v2fly/v2ray-core/v4/common/net" "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/testassist" - "github.com/v2fly/v2ray-core/v4/infra/conf/v4" + v4 "github.com/v2fly/v2ray-core/v4/infra/conf/v4" "github.com/v2fly/v2ray-core/v4/proxy/dokodemo" ) diff --git a/infra/conf/v4/freedom_test.go b/infra/conf/v4/freedom_test.go index 22e54faf0..b015914f3 100644 --- a/infra/conf/v4/freedom_test.go +++ b/infra/conf/v4/freedom_test.go @@ -7,7 +7,7 @@ import ( "github.com/v2fly/v2ray-core/v4/common/protocol" "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/testassist" - "github.com/v2fly/v2ray-core/v4/infra/conf/v4" + v4 "github.com/v2fly/v2ray-core/v4/infra/conf/v4" "github.com/v2fly/v2ray-core/v4/proxy/freedom" ) diff --git a/infra/conf/v4/http_test.go b/infra/conf/v4/http_test.go index d4f91f53a..fe005ba44 100644 --- a/infra/conf/v4/http_test.go +++ b/infra/conf/v4/http_test.go @@ -5,7 +5,7 @@ import ( "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/testassist" - "github.com/v2fly/v2ray-core/v4/infra/conf/v4" + v4 "github.com/v2fly/v2ray-core/v4/infra/conf/v4" "github.com/v2fly/v2ray-core/v4/proxy/http" ) diff --git a/infra/conf/v4/observatory.go b/infra/conf/v4/observatory.go index e7f2acf57..d3f4c6a7f 100644 --- a/infra/conf/v4/observatory.go +++ b/infra/conf/v4/observatory.go @@ -8,7 +8,7 @@ import ( "github.com/v2fly/v2ray-core/v4/app/observatory" "github.com/v2fly/v2ray-core/v4/app/observatory/burst" - "github.com/v2fly/v2ray-core/v4/app/observatory/multiObservatory" + "github.com/v2fly/v2ray-core/v4/app/observatory/multiobservatory" "github.com/v2fly/v2ray-core/v4/common/serial" "github.com/v2fly/v2ray-core/v4/common/taggedfeatures" "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/duration" @@ -32,11 +32,11 @@ type BurstObservatoryConfig struct { } func (b BurstObservatoryConfig) Build() (proto.Message, error) { - if result, err := b.HealthCheck.Build(); err == nil { + result, err := b.HealthCheck.Build() + if err == nil { return &burst.Config{SubjectSelector: b.SubjectSelector, PingConfig: result.(*burst.HealthPingConfig)}, nil - } else { - return nil, err } + return nil, err } type MultiObservatoryItem struct { @@ -50,7 +50,7 @@ type MultiObservatoryConfig struct { } func (o *MultiObservatoryConfig) Build() (proto.Message, error) { - ret := &multiObservatory.Config{Holders: &taggedfeatures.Config{Features: make(map[string]*anypb.Any)}} + ret := &multiobservatory.Config{Holders: &taggedfeatures.Config{Features: make(map[string]*anypb.Any)}} for _, v := range o.Observers { switch v.MemberType { case "burst": @@ -64,7 +64,6 @@ func (o *MultiObservatoryConfig) Build() (proto.Message, error) { return nil, err } ret.Holders.Features[v.Tag] = serial.ToTypedMessage(burstObservatoryConfigPb) - break case "default": fallthrough default: diff --git a/infra/conf/v4/policy_test.go b/infra/conf/v4/policy_test.go index 12f1b714b..7befce24c 100644 --- a/infra/conf/v4/policy_test.go +++ b/infra/conf/v4/policy_test.go @@ -4,7 +4,7 @@ import ( "testing" "github.com/v2fly/v2ray-core/v4/common" - "github.com/v2fly/v2ray-core/v4/infra/conf/v4" + v4 "github.com/v2fly/v2ray-core/v4/infra/conf/v4" ) func TestBufferSize(t *testing.T) { diff --git a/infra/conf/v4/reverse_test.go b/infra/conf/v4/reverse_test.go index ddb0fafec..ffe72ba9a 100644 --- a/infra/conf/v4/reverse_test.go +++ b/infra/conf/v4/reverse_test.go @@ -6,7 +6,7 @@ import ( "github.com/v2fly/v2ray-core/v4/app/reverse" "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/testassist" - "github.com/v2fly/v2ray-core/v4/infra/conf/v4" + v4 "github.com/v2fly/v2ray-core/v4/infra/conf/v4" ) func TestReverseConfig(t *testing.T) { diff --git a/infra/conf/v4/shadowsocks_test.go b/infra/conf/v4/shadowsocks_test.go index b4bfbb48a..36eec081b 100644 --- a/infra/conf/v4/shadowsocks_test.go +++ b/infra/conf/v4/shadowsocks_test.go @@ -8,7 +8,7 @@ import ( "github.com/v2fly/v2ray-core/v4/common/serial" "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/testassist" - "github.com/v2fly/v2ray-core/v4/infra/conf/v4" + v4 "github.com/v2fly/v2ray-core/v4/infra/conf/v4" "github.com/v2fly/v2ray-core/v4/proxy/shadowsocks" ) diff --git a/infra/conf/v4/socks_test.go b/infra/conf/v4/socks_test.go index 7250efad9..9524fe0db 100644 --- a/infra/conf/v4/socks_test.go +++ b/infra/conf/v4/socks_test.go @@ -8,7 +8,7 @@ import ( "github.com/v2fly/v2ray-core/v4/common/serial" "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/testassist" - "github.com/v2fly/v2ray-core/v4/infra/conf/v4" + v4 "github.com/v2fly/v2ray-core/v4/infra/conf/v4" "github.com/v2fly/v2ray-core/v4/proxy/socks" ) diff --git a/infra/conf/v4/transport_test.go b/infra/conf/v4/transport_test.go index 116097386..1e0ca9000 100644 --- a/infra/conf/v4/transport_test.go +++ b/infra/conf/v4/transport_test.go @@ -10,7 +10,7 @@ import ( "github.com/v2fly/v2ray-core/v4/common/serial" "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/socketcfg" "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/testassist" - "github.com/v2fly/v2ray-core/v4/infra/conf/v4" + v4 "github.com/v2fly/v2ray-core/v4/infra/conf/v4" "github.com/v2fly/v2ray-core/v4/transport" "github.com/v2fly/v2ray-core/v4/transport/internet" "github.com/v2fly/v2ray-core/v4/transport/internet/headers/http" diff --git a/infra/conf/v4/v2ray.go b/infra/conf/v4/v2ray.go index 7b02713c9..24194cd0f 100644 --- a/infra/conf/v4/v2ray.go +++ b/infra/conf/v4/v2ray.go @@ -471,7 +471,7 @@ func (c *Config) Build() (*core.Config, error) { " instead of allowing end user to enable it without special tool and knowledge.") sb := strings.Builder{} return nil, newError("Cannot load service").Base(developererr).Base(err).Base(newError(sb.String())) - } else { // nolint: golint + } else { // nolint: revive // Using a else here is required to keep msg in scope config.App = append(config.App, msg...) } diff --git a/infra/conf/v4/v2ray_test.go b/infra/conf/v4/v2ray_test.go index a110c8884..3e4db1dfd 100644 --- a/infra/conf/v4/v2ray_test.go +++ b/infra/conf/v4/v2ray_test.go @@ -25,7 +25,7 @@ import ( // Geo loaders _ "github.com/v2fly/v2ray-core/v4/infra/conf/geodata/memconservative" _ "github.com/v2fly/v2ray-core/v4/infra/conf/geodata/standard" - "github.com/v2fly/v2ray-core/v4/infra/conf/v4" + v4 "github.com/v2fly/v2ray-core/v4/infra/conf/v4" "github.com/v2fly/v2ray-core/v4/proxy/blackhole" dns_proxy "github.com/v2fly/v2ray-core/v4/proxy/dns" "github.com/v2fly/v2ray-core/v4/proxy/freedom" diff --git a/infra/conf/v4/vless_test.go b/infra/conf/v4/vless_test.go index 9b1ca47bf..01995614b 100644 --- a/infra/conf/v4/vless_test.go +++ b/infra/conf/v4/vless_test.go @@ -8,7 +8,7 @@ import ( "github.com/v2fly/v2ray-core/v4/common/serial" "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/testassist" - "github.com/v2fly/v2ray-core/v4/infra/conf/v4" + v4 "github.com/v2fly/v2ray-core/v4/infra/conf/v4" "github.com/v2fly/v2ray-core/v4/proxy/vless" "github.com/v2fly/v2ray-core/v4/proxy/vless/inbound" "github.com/v2fly/v2ray-core/v4/proxy/vless/outbound" diff --git a/infra/conf/v4/vmess_test.go b/infra/conf/v4/vmess_test.go index c84fadda2..339529d32 100644 --- a/infra/conf/v4/vmess_test.go +++ b/infra/conf/v4/vmess_test.go @@ -8,7 +8,7 @@ import ( "github.com/v2fly/v2ray-core/v4/common/serial" "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/testassist" - "github.com/v2fly/v2ray-core/v4/infra/conf/v4" + v4 "github.com/v2fly/v2ray-core/v4/infra/conf/v4" "github.com/v2fly/v2ray-core/v4/proxy/vmess" "github.com/v2fly/v2ray-core/v4/proxy/vmess/inbound" "github.com/v2fly/v2ray-core/v4/proxy/vmess/outbound" diff --git a/infra/conf/v5cfg/common.go b/infra/conf/v5cfg/common.go index 49aaae3b0..bb1e1d2bc 100644 --- a/infra/conf/v5cfg/common.go +++ b/infra/conf/v5cfg/common.go @@ -11,16 +11,16 @@ import ( "github.com/v2fly/v2ray-core/v4/common/registry" ) -func loadHeterogeneousConfigFromRawJson(interfaceType, name string, rawJson json.RawMessage) (proto.Message, error) { +func loadHeterogeneousConfigFromRawJSON(interfaceType, name string, rawJSON json.RawMessage) (proto.Message, error) { fsdef := envimpl.NewDefaultFileSystemDefaultImpl() ctx := envctx.ContextWithEnvironment(context.TODO(), fsdef) - if rawJson == nil || len(rawJson) == 0 { - rawJson = []byte("{}") + if rawJSON == nil || len(rawJSON) == 0 { + rawJSON = []byte("{}") } - return registry.LoadImplementationByAlias(ctx, interfaceType, name, []byte(rawJson)) + return registry.LoadImplementationByAlias(ctx, interfaceType, name, []byte(rawJSON)) } -// LoadHeterogeneousConfigFromRawJson private API -func LoadHeterogeneousConfigFromRawJson(ctx context.Context, interfaceType, name string, rawJson json.RawMessage) (proto.Message, error) { - return loadHeterogeneousConfigFromRawJson(interfaceType, name, rawJson) +// LoadHeterogeneousConfigFromRawJSON private API +func LoadHeterogeneousConfigFromRawJSON(ctx context.Context, interfaceType, name string, rawJSON json.RawMessage) (proto.Message, error) { + return loadHeterogeneousConfigFromRawJSON(interfaceType, name, rawJSON) } diff --git a/infra/conf/v5cfg/inbound.go b/infra/conf/v5cfg/inbound.go index f26241af5..b28725d47 100644 --- a/infra/conf/v5cfg/inbound.go +++ b/infra/conf/v5cfg/inbound.go @@ -64,7 +64,7 @@ func (c InboundConfig) BuildV5(ctx context.Context) (proto.Message, error) { c.Settings = []byte("{}") } - inboundConfigPack, err := loadHeterogeneousConfigFromRawJson("inbound", c.Protocol, c.Settings) + inboundConfigPack, err := loadHeterogeneousConfigFromRawJSON("inbound", c.Protocol, c.Settings) if err != nil { return nil, newError("unable to load inbound protocol config").Base(err) } diff --git a/infra/conf/v5cfg/init.go b/infra/conf/v5cfg/init.go index aa4b69893..50a0a3627 100644 --- a/infra/conf/v5cfg/init.go +++ b/infra/conf/v5cfg/init.go @@ -26,13 +26,13 @@ func init() { if err != nil { return nil, err } - return loadJsonConfig(data) + return loadJSONConfig(data) case io.Reader: data, err := buf.ReadAllToBytes(v) if err != nil { return nil, err } - return loadJsonConfig(data) + return loadJSONConfig(data) default: return nil, newError("unknown type") } diff --git a/infra/conf/v5cfg/outbound.go b/infra/conf/v5cfg/outbound.go index 889c1bb0d..e923d1558 100644 --- a/infra/conf/v5cfg/outbound.go +++ b/infra/conf/v5cfg/outbound.go @@ -46,7 +46,7 @@ func (c OutboundConfig) BuildV5(ctx context.Context) (proto.Message, error) { c.Settings = []byte("{}") } - outboundConfigPack, err := loadHeterogeneousConfigFromRawJson("outbound", c.Protocol, c.Settings) + outboundConfigPack, err := loadHeterogeneousConfigFromRawJSON("outbound", c.Protocol, c.Settings) if err != nil { return nil, newError("unable to load outbound protocol config").Base(err) } diff --git a/infra/conf/v5cfg/root.go b/infra/conf/v5cfg/root.go index 2ea64c2a0..87a417a39 100644 --- a/infra/conf/v5cfg/root.go +++ b/infra/conf/v5cfg/root.go @@ -28,7 +28,7 @@ func (c RootConfig) BuildV5(ctx context.Context) (proto.Message, error) { var logConfMsg *anypb.Any if c.LogConfig != nil { - logConfMsgUnpacked, err := loadHeterogeneousConfigFromRawJson("service", "log", c.LogConfig) + logConfMsgUnpacked, err := loadHeterogeneousConfigFromRawJSON("service", "log", c.LogConfig) if err != nil { return nil, err } @@ -41,7 +41,7 @@ func (c RootConfig) BuildV5(ctx context.Context) (proto.Message, error) { config.App = append([]*anypb.Any{logConfMsg}, config.App...) if c.RouterConfig != nil { - routerConfig, err := loadHeterogeneousConfigFromRawJson("service", "router", c.RouterConfig) + routerConfig, err := loadHeterogeneousConfigFromRawJSON("service", "router", c.RouterConfig) if err != nil { return nil, err } @@ -49,7 +49,7 @@ func (c RootConfig) BuildV5(ctx context.Context) (proto.Message, error) { } if c.DNSConfig != nil { - dnsApp, err := loadHeterogeneousConfigFromRawJson("service", "dns", c.DNSConfig) + dnsApp, err := loadHeterogeneousConfigFromRawJSON("service", "dns", c.DNSConfig) if err != nil { return nil, newError("failed to parse DNS config").Base(err) } @@ -73,7 +73,7 @@ func (c RootConfig) BuildV5(ctx context.Context) (proto.Message, error) { } for serviceName, service := range c.Services { - servicePackedConfig, err := loadHeterogeneousConfigFromRawJson("service", serviceName, service) + servicePackedConfig, err := loadHeterogeneousConfigFromRawJSON("service", serviceName, service) if err != nil { return nil, err } @@ -82,7 +82,7 @@ func (c RootConfig) BuildV5(ctx context.Context) (proto.Message, error) { return config, nil } -func loadJsonConfig(data []byte) (*core.Config, error) { +func loadJSONConfig(data []byte) (*core.Config, error) { rootConfig := &RootConfig{} err := json.Unmarshal(data, rootConfig) diff --git a/infra/conf/v5cfg/stream.go b/infra/conf/v5cfg/stream.go index 14c6a438e..71684ba9b 100644 --- a/infra/conf/v5cfg/stream.go +++ b/infra/conf/v5cfg/stream.go @@ -22,7 +22,7 @@ func (s StreamConfig) BuildV5(ctx context.Context) (proto.Message, error) { if s.TransportSettings == nil { s.TransportSettings = []byte("{}") } - transportConfigPack, err := loadHeterogeneousConfigFromRawJson("transport", s.Transport, s.TransportSettings) + transportConfigPack, err := loadHeterogeneousConfigFromRawJSON("transport", s.Transport, s.TransportSettings) if err != nil { return nil, newError("unable to load transport config").Base(err) } @@ -37,7 +37,7 @@ func (s StreamConfig) BuildV5(ctx context.Context) (proto.Message, error) { if s.SecuritySettings == nil { s.SecuritySettings = []byte("{}") } - securityConfigPack, err := loadHeterogeneousConfigFromRawJson("security", s.Security, s.SecuritySettings) + securityConfigPack, err := loadHeterogeneousConfigFromRawJSON("security", s.Security, s.SecuritySettings) if err != nil { return nil, newError("unable to load security config").Base(err) } diff --git a/main/commands/all/api/shared.go b/main/commands/all/api/shared.go index 64d8b6e49..fa49ac220 100644 --- a/main/commands/all/api/shared.go +++ b/main/commands/all/api/shared.go @@ -80,7 +80,7 @@ func dialAPIServerWithContext(ctx context.Context) (conn *grpc.ClientConn) { return } -func protoToJSONString(m proto.Message, prefix, indent string) (string, error) { +func protoToJSONString(m proto.Message, prefix, indent string) (string, error) { // nolint: unparam return strings.TrimSpace(protojson.MarshalOptions{Indent: indent}.Format(m)), nil } diff --git a/main/commands/all/engineering/convertpb.go b/main/commands/all/engineering/convertpb.go index 13c1eebd2..2b12822b1 100644 --- a/main/commands/all/engineering/convertpb.go +++ b/main/commands/all/engineering/convertpb.go @@ -41,11 +41,9 @@ var cmdConvertPb = &base.Command{ if len(configFiles) == 0 { base.Fatalf("%s", newError("failed to load config").Base(err)) return - - } else { - base.Fatalf("%s", newError(fmt.Sprintf("failed to load config: %s", configFiles)).Base(err)) - return } + base.Fatalf("%s", newError(fmt.Sprintf("failed to load config: %s", configFiles)).Base(err)) + return } bytew, err := proto.Marshal(config) if err != nil { diff --git a/main/commands/all/engineering/reversepb.go b/main/commands/all/engineering/reversepb.go index 7682338bf..df75a6afb 100644 --- a/main/commands/all/engineering/reversepb.go +++ b/main/commands/all/engineering/reversepb.go @@ -31,7 +31,7 @@ var cmdReversePb = &base.Command{ } switch *configFormat { case "jsonpb": - if err := jsonpb.DumpJsonPb(&conf, os.Stdout); err != nil { + if err := jsonpb.DumpJSONPb(&conf, os.Stdout); err != nil { base.Fatalf("%s", err) } case "v2jsonpb": diff --git a/main/commands/all/jsonv4/convert.go b/main/commands/all/jsonv4/convert.go index 32ac9c723..901de7732 100644 --- a/main/commands/all/jsonv4/convert.go +++ b/main/commands/all/jsonv4/convert.go @@ -136,7 +136,7 @@ func executeConvert(cmd *base.Command, args []string) { base.Fatalf(err.Error()) } w := bytes.NewBuffer(nil) - err = jsonpb.DumpJsonPb(pbConfig, w) + err = jsonpb.DumpJSONPb(pbConfig, w) if err != nil { base.Fatalf(err.Error()) } diff --git a/main/commands/helpers/config_load.go b/main/commands/helpers/config_load.go index f486fbb50..0620f6d49 100644 --- a/main/commands/helpers/config_load.go +++ b/main/commands/helpers/config_load.go @@ -7,7 +7,7 @@ import ( "github.com/v2fly/v2ray-core/v4/infra/conf/merge" "github.com/v2fly/v2ray-core/v4/infra/conf/mergers" "github.com/v2fly/v2ray-core/v4/infra/conf/serial" - "github.com/v2fly/v2ray-core/v4/infra/conf/v4" + v4 "github.com/v2fly/v2ray-core/v4/infra/conf/v4" ) // LoadConfig load config files to *conf.Config, it will: diff --git a/main/distro/all/all.go b/main/distro/all/all.go index 19f30dd1f..aa89ad021 100644 --- a/main/distro/all/all.go +++ b/main/distro/all/all.go @@ -33,7 +33,7 @@ import ( // Developer preview features _ "github.com/v2fly/v2ray-core/v4/app/instman" _ "github.com/v2fly/v2ray-core/v4/app/observatory" - _ "github.com/v2fly/v2ray-core/v4/app/restful-api" + _ "github.com/v2fly/v2ray-core/v4/app/restfulapi" // Inbound and outbound proxies. _ "github.com/v2fly/v2ray-core/v4/proxy/blackhole" @@ -89,6 +89,7 @@ import ( // V5 version of json configure file parser _ "github.com/v2fly/v2ray-core/v4/infra/conf/v5cfg" + // Simplified config _ "github.com/v2fly/v2ray-core/v4/proxy/http/simplified" _ "github.com/v2fly/v2ray-core/v4/proxy/shadowsocks/simplified" _ "github.com/v2fly/v2ray-core/v4/proxy/socks/simplified" diff --git a/main/v2binding/v2binding.go b/main/v2binding/v2binding.go index c00df1658..36e87ac19 100644 --- a/main/v2binding/v2binding.go +++ b/main/v2binding/v2binding.go @@ -12,6 +12,8 @@ import ( "github.com/v2fly/v2ray-core/v4/app/router" "github.com/v2fly/v2ray-core/v4/common/net" "github.com/v2fly/v2ray-core/v4/common/serial" + + // Initialization _ "github.com/v2fly/v2ray-core/v4/main/distro/all" "github.com/v2fly/v2ray-core/v4/proxy/blackhole" "github.com/v2fly/v2ray-core/v4/proxy/dokodemo" @@ -77,7 +79,6 @@ func (b *bindingInstance) startAPIInstance() { panic(err) } b.instance = instance - return } func withDefaultApps(config *core.Config) *core.Config { diff --git a/proxy/shadowsocks/protocol.go b/proxy/shadowsocks/protocol.go index 6c0c54f96..1cf5c5797 100644 --- a/proxy/shadowsocks/protocol.go +++ b/proxy/shadowsocks/protocol.go @@ -146,7 +146,7 @@ func ReadTCPResponse(user *protocol.MemoryUser, reader io.Reader) (buf.Reader, e iv = make([]byte, account.Cipher.IVSize()) if n, err := io.ReadFull(reader, iv); err != nil { return nil, newError("failed to read IV").Base(err) - } else { // nolint: golint + } else { // nolint: revive drainer.AcknowledgeReceive(n) } } diff --git a/proxy/vmess/encoding/client.go b/proxy/vmess/encoding/client.go index d5412ee75..96837c36c 100644 --- a/proxy/vmess/encoding/client.go +++ b/proxy/vmess/encoding/client.go @@ -239,12 +239,12 @@ func (c *ClientSession) DecodeResponseHeader(reader io.Reader) (*protocol.Respon if n, err := io.ReadFull(reader, aeadEncryptedResponseHeaderLength[:]); err != nil { c.readDrainer.AcknowledgeReceive(n) return nil, drain.WithError(c.readDrainer, reader, newError("Unable to Read Header Len").Base(err)) - } else { // nolint: golint + } else { // nolint: revive c.readDrainer.AcknowledgeReceive(n) } if decryptedResponseHeaderLengthBinaryBuffer, err := aeadResponseHeaderLengthEncryptionAEAD.Open(nil, aeadResponseHeaderLengthEncryptionIV, aeadEncryptedResponseHeaderLength[:], nil); err != nil { return nil, drain.WithError(c.readDrainer, reader, newError("Failed To Decrypt Length").Base(err)) - } else { // nolint: golint + } else { // nolint: revive common.Must(binary.Read(bytes.NewReader(decryptedResponseHeaderLengthBinaryBuffer), binary.BigEndian, &decryptedResponseHeaderLengthBinaryDeserializeBuffer)) decryptedResponseHeaderLength = int(decryptedResponseHeaderLengthBinaryDeserializeBuffer) } @@ -260,13 +260,13 @@ func (c *ClientSession) DecodeResponseHeader(reader io.Reader) (*protocol.Respon if n, err := io.ReadFull(reader, encryptedResponseHeaderBuffer); err != nil { c.readDrainer.AcknowledgeReceive(n) return nil, drain.WithError(c.readDrainer, reader, newError("Unable to Read Header Data").Base(err)) - } else { // nolint: golint + } else { // nolint: revive c.readDrainer.AcknowledgeReceive(n) } if decryptedResponseHeaderBuffer, err := aeadResponseHeaderPayloadEncryptionAEAD.Open(nil, aeadResponseHeaderPayloadEncryptionIV, encryptedResponseHeaderBuffer, nil); err != nil { return nil, drain.WithError(c.readDrainer, reader, newError("Failed To Decrypt Payload").Base(err)) - } else { // nolint: golint + } else { // nolint: revive c.responseReader = bytes.NewReader(decryptedResponseHeaderBuffer) } } diff --git a/transport/internet/headers/http/http.go b/transport/internet/headers/http/http.go index 54611889b..c1d630263 100644 --- a/transport/internet/headers/http/http.go +++ b/transport/internet/headers/http/http.go @@ -112,7 +112,7 @@ func (h *HeaderReader) Read(reader io.Reader) (*buf.Buffer, error) { // Parse the request if req, err := readRequest(bufio.NewReader(bytes.NewReader(headerBuf.Bytes()))); err != nil { return nil, err - } else { // nolint: golint + } else { // nolint: revive h.req = req } diff --git a/transport/internet/kcp/io.go b/transport/internet/kcp/io.go index 11712e348..e03a5c2e1 100644 --- a/transport/internet/kcp/io.go +++ b/transport/internet/kcp/io.go @@ -19,7 +19,7 @@ type PacketWriter interface { io.Writer } -type KCPPacketReader struct { // nolint: golint +type KCPPacketReader struct { // nolint: revive Security cipher.AEAD Header internet.PacketHeader } @@ -55,7 +55,7 @@ func (r *KCPPacketReader) Read(b []byte) []Segment { return result } -type KCPPacketWriter struct { // nolint: golint +type KCPPacketWriter struct { // nolint: revive Header internet.PacketHeader Security cipher.AEAD Writer io.Writer diff --git a/transport/internet/sockopt_darwin.go b/transport/internet/sockopt_darwin.go index c4b2e8deb..a77ffac8f 100644 --- a/transport/internet/sockopt_darwin.go +++ b/transport/internet/sockopt_darwin.go @@ -6,11 +6,11 @@ import ( const ( // TCP_FASTOPEN is the socket option on darwin for TCP fast open. - TCP_FASTOPEN = 0x105 // nolint: golint,stylecheck + TCP_FASTOPEN = 0x105 // nolint: revive,stylecheck // TCP_FASTOPEN_SERVER is the value to enable TCP fast open on darwin for server connections. - TCP_FASTOPEN_SERVER = 0x01 // nolint: golint,stylecheck + TCP_FASTOPEN_SERVER = 0x01 // nolint: revive,stylecheck // TCP_FASTOPEN_CLIENT is the value to enable TCP fast open on darwin for client connections. - TCP_FASTOPEN_CLIENT = 0x02 // nolint: golint,stylecheck + TCP_FASTOPEN_CLIENT = 0x02 // nolint: revive,stylecheck ) func applyOutboundSocketOptions(network string, address string, fd uintptr, config *SocketConfig) error { diff --git a/transport/internet/sockopt_linux.go b/transport/internet/sockopt_linux.go index dc2f36e1a..0ec2995ae 100644 --- a/transport/internet/sockopt_linux.go +++ b/transport/internet/sockopt_linux.go @@ -9,9 +9,9 @@ import ( const ( // For incoming connections. - TCP_FASTOPEN = 23 // nolint: golint,stylecheck + TCP_FASTOPEN = 23 // nolint: revive,stylecheck // For out-going connections. - TCP_FASTOPEN_CONNECT = 30 // nolint: golint,stylecheck + TCP_FASTOPEN_CONNECT = 30 // nolint: revive,stylecheck ) func bindAddr(fd uintptr, ip []byte, port uint32) error { diff --git a/transport/internet/sockopt_windows.go b/transport/internet/sockopt_windows.go index 0f8d475d8..2c990b643 100644 --- a/transport/internet/sockopt_windows.go +++ b/transport/internet/sockopt_windows.go @@ -3,7 +3,7 @@ package internet import "syscall" const ( - TCP_FASTOPEN = 15 // nolint: golint,stylecheck + TCP_FASTOPEN = 15 // nolint: revive,stylecheck ) func setTFO(fd syscall.Handle, settings SocketConfig_TCPFastOpenState) error { diff --git a/transport/internet/system_listener.go b/transport/internet/system_listener.go index 435cce421..d59aa623d 100644 --- a/transport/internet/system_listener.go +++ b/transport/internet/system_listener.go @@ -70,7 +70,7 @@ func (dl *DefaultListener) Listen(ctx context.Context, addr net.Addr, sockopt *S if err != nil { return nil, err } - ctx = context.WithValue(ctx, address, locker) // nolint: golint,staticcheck + ctx = context.WithValue(ctx, address, locker) // nolint: revive,staticcheck } } diff --git a/transport/internet/tcp/sockopt_linux.go b/transport/internet/tcp/sockopt_linux.go index b6ac9a0b5..ee689d7ab 100644 --- a/transport/internet/tcp/sockopt_linux.go +++ b/transport/internet/tcp/sockopt_linux.go @@ -10,7 +10,7 @@ import ( "github.com/v2fly/v2ray-core/v4/transport/internet" ) -const SO_ORIGINAL_DST = 80 // nolint: golint,stylecheck +const SO_ORIGINAL_DST = 80 // nolint: revive,stylecheck func GetOriginalDestination(conn internet.Connection) (net.Destination, error) { sysrawconn, f := conn.(syscall.Conn)