github.com/xmplusdev/xray-core@v1.8.10/app/observatory/command/command.go (about)

     1  package command
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/xmplusdev/xray-core/app/observatory"
     7  	"github.com/xmplusdev/xray-core/common"
     8  	core "github.com/xmplusdev/xray-core/core"
     9  	"github.com/xmplusdev/xray-core/features/extension"
    10  	"google.golang.org/grpc"
    11  )
    12  
    13  type service struct {
    14  	UnimplementedObservatoryServiceServer
    15  	v *core.Instance
    16  
    17  	observatory extension.Observatory
    18  }
    19  
    20  func (s *service) GetOutboundStatus(ctx context.Context, request *GetOutboundStatusRequest) (*GetOutboundStatusResponse, error) {
    21  	resp, err := s.observatory.GetObservation(ctx)
    22  	if err != nil {
    23  		return nil, err
    24  	}
    25  	retdata := resp.(*observatory.ObservationResult)
    26  	return &GetOutboundStatusResponse{
    27  		Status: retdata,
    28  	}, nil
    29  }
    30  
    31  func (s *service) Register(server *grpc.Server) {
    32  	RegisterObservatoryServiceServer(server, s)
    33  }
    34  
    35  func init() {
    36  	common.Must(common.RegisterConfig((*Config)(nil), func(ctx context.Context, cfg interface{}) (interface{}, error) {
    37  		s := core.MustFromContext(ctx)
    38  		sv := &service{v: s}
    39  		err := s.RequireFeatures(func(Observatory extension.Observatory) {
    40  			sv.observatory = Observatory
    41  		})
    42  		if err != nil {
    43  			return nil, err
    44  		}
    45  		return sv, nil
    46  	}))
    47  }