github.com/yandex/pandora@v0.5.32/components/guns/http_scenario/import.go (about)

     1  package httpscenario
     2  
     3  import (
     4  	"github.com/spf13/afero"
     5  	phttp "github.com/yandex/pandora/components/guns/http"
     6  	"github.com/yandex/pandora/core"
     7  	"github.com/yandex/pandora/core/aggregator/netsample"
     8  	"github.com/yandex/pandora/core/register"
     9  	"github.com/yandex/pandora/lib/answlog"
    10  )
    11  
    12  func WrapGun(g Gun) core.Gun {
    13  	if g == nil {
    14  		return nil
    15  	}
    16  	return &gunWrapper{Gun: g}
    17  }
    18  
    19  type gunWrapper struct {
    20  	Gun Gun
    21  }
    22  
    23  func (g *gunWrapper) Shoot(ammo core.Ammo) {
    24  	g.Gun.Shoot(ammo.(*Scenario))
    25  }
    26  
    27  func (g *gunWrapper) Bind(a core.Aggregator, deps core.GunDeps) error {
    28  	return g.Gun.Bind(netsample.UnwrapAggregator(a), deps)
    29  }
    30  
    31  func Import(fs afero.Fs) {
    32  	register.Gun("http/scenario", func(conf phttp.GunConfig) func() core.Gun {
    33  		targetResolved, _ := phttp.PreResolveTargetAddr(&conf.Client, conf.Target)
    34  		conf.TargetResolved = targetResolved
    35  		answLog := answlog.Init(conf.AnswLog.Path, conf.AnswLog.Enabled)
    36  		return func() core.Gun {
    37  			gun := NewHTTPGun(conf, answLog)
    38  			return WrapGun(gun)
    39  		}
    40  	}, phttp.DefaultHTTPGunConfig)
    41  
    42  	register.Gun("http2/scenario", func(conf phttp.GunConfig) func() (core.Gun, error) {
    43  		targetResolved, _ := phttp.PreResolveTargetAddr(&conf.Client, conf.Target)
    44  		conf.TargetResolved = targetResolved
    45  		answLog := answlog.Init(conf.AnswLog.Path, conf.AnswLog.Enabled)
    46  		return func() (core.Gun, error) {
    47  			gun, err := NewHTTP2Gun(conf, answLog)
    48  			return WrapGun(gun), err
    49  		}
    50  	}, phttp.DefaultHTTP2GunConfig)
    51  }