github.com/v2fly/v2ray-core/v5@v5.16.2-0.20240507031116-8191faa6e095/app/observatory/multiobservatory/multi.go (about)

     1  package multiobservatory
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/golang/protobuf/jsonpb"
     7  	"github.com/golang/protobuf/proto"
     8  
     9  	"github.com/v2fly/v2ray-core/v5/common"
    10  	"github.com/v2fly/v2ray-core/v5/common/taggedfeatures"
    11  	"github.com/v2fly/v2ray-core/v5/features"
    12  	"github.com/v2fly/v2ray-core/v5/features/extension"
    13  )
    14  
    15  type Observer struct {
    16  	features.TaggedFeatures
    17  	config *Config
    18  	ctx    context.Context
    19  }
    20  
    21  func (o Observer) GetObservation(ctx context.Context) (proto.Message, error) {
    22  	return common.Must2(o.GetFeaturesByTag("")).(extension.Observatory).GetObservation(ctx)
    23  }
    24  
    25  func (o Observer) Type() interface{} {
    26  	return extension.ObservatoryType()
    27  }
    28  
    29  func New(ctx context.Context, config *Config) (*Observer, error) {
    30  	holder, err := taggedfeatures.NewHolderFromConfig(ctx, config.Holders, extension.ObservatoryType())
    31  	if err != nil {
    32  		return nil, err
    33  	}
    34  	return &Observer{config: config, ctx: ctx, TaggedFeatures: holder}, nil
    35  }
    36  
    37  func (x *Config) UnmarshalJSONPB(unmarshaler *jsonpb.Unmarshaler, bytes []byte) error {
    38  	var err error
    39  	x.Holders, err = taggedfeatures.LoadJSONConfig(context.TODO(), "service", "background", bytes)
    40  	return err
    41  }
    42  
    43  func init() {
    44  	common.Must(common.RegisterConfig((*Config)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
    45  		return New(ctx, config.(*Config))
    46  	}))
    47  }