Browse Source

apply coding style

Shelikhoo 4 years ago
parent
commit
459a914ab7

+ 3 - 1
app/observatory/command/command.go

@@ -2,11 +2,13 @@ package command
 
 import (
 	"context"
+
+	"google.golang.org/grpc"
+
 	core "github.com/v2fly/v2ray-core/v4"
 	"github.com/v2fly/v2ray-core/v4/app/observatory"
 	"github.com/v2fly/v2ray-core/v4/common"
 	"github.com/v2fly/v2ray-core/v4/features/extension"
-	"google.golang.org/grpc"
 )
 
 type service struct {

+ 2 - 7
app/observatory/command/command.pb.go

@@ -1,13 +1,12 @@
 // Code generated by protoc-gen-go. DO NOT EDIT.
 // versions:
-// 	protoc-gen-go v1.25.0
-// 	protoc        v3.13.0
+// 	protoc-gen-go v1.26.0
+// 	protoc        v3.15.6
 // source: app/observatory/command/command.proto
 
 package command
 
 import (
-	proto "github.com/golang/protobuf/proto"
 	observatory "github.com/v2fly/v2ray-core/v4/app/observatory"
 	protoreflect "google.golang.org/protobuf/reflect/protoreflect"
 	protoimpl "google.golang.org/protobuf/runtime/protoimpl"
@@ -22,10 +21,6 @@ const (
 	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
 )
 
-// This is a compile-time assertion that a sufficiently up-to-date version
-// of the legacy proto package is being used.
-const _ = proto.ProtoPackageIsVersion4
-
 type GetOutboundStatusRequest struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache

+ 2 - 7
app/observatory/config.pb.go

@@ -1,13 +1,12 @@
 // Code generated by protoc-gen-go. DO NOT EDIT.
 // versions:
-// 	protoc-gen-go v1.25.0
-// 	protoc        v3.13.0
+// 	protoc-gen-go v1.26.0
+// 	protoc        v3.15.6
 // source: app/observatory/config.proto
 
 package observatory
 
 import (
-	proto "github.com/golang/protobuf/proto"
 	protoreflect "google.golang.org/protobuf/reflect/protoreflect"
 	protoimpl "google.golang.org/protobuf/runtime/protoimpl"
 	reflect "reflect"
@@ -21,10 +20,6 @@ const (
 	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
 )
 
-// This is a compile-time assertion that a sufficiently up-to-date version
-// of the legacy proto package is being used.
-const _ = proto.ProtoPackageIsVersion4
-
 type ObservationResult struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache

+ 7 - 5
app/observatory/observer.go

@@ -4,7 +4,14 @@ package observatory
 
 import (
 	"context"
+	"net"
+	"net/http"
+	"net/url"
+	"sync"
+	"time"
+
 	"github.com/golang/protobuf/proto"
+
 	core "github.com/v2fly/v2ray-core/v4"
 	"github.com/v2fly/v2ray-core/v4/common"
 	v2net "github.com/v2fly/v2ray-core/v4/common/net"
@@ -14,11 +21,6 @@ import (
 	"github.com/v2fly/v2ray-core/v4/features/extension"
 	"github.com/v2fly/v2ray-core/v4/features/outbound"
 	"github.com/v2fly/v2ray-core/v4/transport/internet/tagged"
-	"net"
-	"net/http"
-	"net/url"
-	"sync"
-	"time"
 )
 
 type Observer struct {

+ 17 - 5
app/router/config.go

@@ -160,9 +160,21 @@ func (rr *RoutingRule) BuildCondition() (Condition, error) {
 }
 
 func (br *BalancingRule) Build(ohm outbound.Manager) (*Balancer, error) {
-	return &Balancer{
-		selectors: br.OutboundSelector,
-		strategy:  &RandomStrategy{},
-		ohm:       ohm,
-	}, nil
+	switch br.Strategy {
+	case "leastPing":
+		return &Balancer{
+			selectors: br.OutboundSelector,
+			strategy:  &LeastPingStrategy{},
+			ohm:       ohm,
+		}, nil
+	case "random":
+		fallthrough
+	default:
+		return &Balancer{
+			selectors: br.OutboundSelector,
+			strategy:  &RandomStrategy{},
+			ohm:       ohm,
+		}, nil
+
+	}
 }

+ 2 - 1
infra/conf/api.go

@@ -1,9 +1,10 @@
 package conf
 
 import (
+	"strings"
+
 	"github.com/jhump/protoreflect/desc"
 	"github.com/jhump/protoreflect/dynamic"
-	"strings"
 
 	"github.com/v2fly/v2ray-core/v4/app/commander"
 	loggerservice "github.com/v2fly/v2ray-core/v4/app/log/command"

+ 2 - 0
infra/conf/services.go

@@ -2,9 +2,11 @@ package conf
 
 import (
 	"encoding/json"
+
 	"github.com/golang/protobuf/jsonpb"
 	"github.com/jhump/protoreflect/desc"
 	"github.com/jhump/protoreflect/dynamic"
+
 	"github.com/v2fly/v2ray-core/v4/common/serial"
 )
 

+ 3 - 2
infra/conf/v2ray.go

@@ -2,12 +2,13 @@ package conf
 
 import (
 	"encoding/json"
-	"google.golang.org/protobuf/reflect/protoreflect"
-	"google.golang.org/protobuf/reflect/protoregistry"
 	"log"
 	"os"
 	"strings"
 
+	"google.golang.org/protobuf/reflect/protoreflect"
+	"google.golang.org/protobuf/reflect/protoregistry"
+
 	core "github.com/v2fly/v2ray-core/v4"
 	"github.com/v2fly/v2ray-core/v4/app/dispatcher"
 	"github.com/v2fly/v2ray-core/v4/app/proxyman"