1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-10 01:40:44 +00:00
v2fly/app/observatory/command/command.go

52 lines
1.2 KiB
Go
Raw Normal View History

//go:build !confonly
2021-04-12 00:24:10 +00:00
// +build !confonly
2021-03-06 19:09:26 +00:00
package command
import (
"context"
2021-04-08 19:56:04 +00:00
"google.golang.org/grpc"
2021-03-06 19:09:26 +00: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 21:08:27 +00:00
observatory extension.Observatory
2021-03-06 19:09:26 +00:00
}
func (s *service) GetOutboundStatus(ctx context.Context, request *GetOutboundStatusRequest) (*GetOutboundStatusResponse, error) {
2021-03-06 21:08:27 +00:00
resp, err := s.observatory.GetObservation(ctx)
2021-03-06 19:09:26 +00: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 21:08:27 +00: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 19:09:26 +00:00
}))
}