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