Browse Source

add support for tagged observer

Shelikhoo 4 years ago
parent
commit
89a82ece8b
1 changed files with 18 additions and 4 deletions
  1. 18 4
      app/observatory/command/command.go

+ 18 - 4
app/observatory/command/command.go

@@ -3,8 +3,12 @@
 
 package command
 
+//go:generate go run github.com/v2fly/v2ray-core/v4/common/errors/errorgen
+
 import (
 	"context"
+	"github.com/golang/protobuf/proto"
+	"github.com/v2fly/v2ray-core/v4/features"
 
 	"google.golang.org/grpc"
 
@@ -22,11 +26,21 @@ type service struct {
 }
 
 func (s *service) GetOutboundStatus(ctx context.Context, request *GetOutboundStatusRequest) (*GetOutboundStatusResponse, error) {
-	resp, err := s.observatory.GetObservation(ctx)
-	if err != nil {
-		return nil, err
+	var result proto.Message
+	if request.Tag == "" {
+		observeResult, err := s.observatory.GetObservation(ctx)
+		if err != nil {
+			newError("cannot get observation").Base(err)
+		}
+		result = observeResult
+	} else {
+		observeResult, err := common.Must2(s.observatory.(features.TaggedFeatures).GetFeaturesByTag(request.Tag)).(extension.Observatory).GetObservation(s.ctx)
+		if err != nil {
+			newError("cannot get observation").Base(err)
+		}
+		result = observeResult
 	}
-	retdata := resp.(*observatory.ObservationResult)
+	retdata := result.(*observatory.ObservationResult)
 	return &GetOutboundStatusResponse{
 		Status: retdata,
 	}, nil