1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-07-07 22:04:30 -04:00
v2fly/app/observatory/command/command.go

52 lines
1.2 KiB
Go
Raw Normal View History

//go:build !confonly
2021-04-11 20:24:10 -04:00
// +build !confonly
2021-03-06 14:09:26 -05:00
package command
import (
"context"
2021-04-08 15:56:04 -04:00
"google.golang.org/grpc"
2021-03-06 14:09:26 -05:00
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"
)
type service struct {
UnimplementedObservatoryServiceServer
v *core.Instance
2021-03-06 16:08:27 -05:00
observatory extension.Observatory
2021-03-06 14:09:26 -05:00
}
func (s *service) GetOutboundStatus(ctx context.Context, request *GetOutboundStatusRequest) (*GetOutboundStatusResponse, error) {
2021-03-06 16:08:27 -05:00
resp, err := s.observatory.GetObservation(ctx)
2021-03-06 14:09:26 -05:00
if err != nil {
return nil, err
}
retdata := resp.(*observatory.ObservationResult)
return &GetOutboundStatusResponse{
Status: retdata,
}, nil
}
func (s *service) Register(server *grpc.Server) {
RegisterObservatoryServiceServer(server, s)
}
func init() {
common.Must(common.RegisterConfig((*Config)(nil), func(ctx context.Context, cfg interface{}) (interface{}, error) {
s := core.MustFromContext(ctx)
2021-03-06 16:08:27 -05:00
sv := &service{v: s}
err := s.RequireFeatures(func(Observatory extension.Observatory) {
sv.observatory = Observatory
})
if err != nil {
return nil, err
}
return sv, nil
2021-03-06 14:09:26 -05:00
}))
}