github.com/yandex/pandora@v0.5.32/components/providers/scenario/grpc/provider.go (about) 1 package grpc 2 3 import ( 4 "fmt" 5 6 "github.com/spf13/afero" 7 gun "github.com/yandex/pandora/components/guns/grpc/scenario" 8 "github.com/yandex/pandora/components/providers/scenario" 9 "github.com/yandex/pandora/components/providers/scenario/config" 10 "github.com/yandex/pandora/core" 11 ) 12 13 var _ core.Provider = (*scenario.Provider[*gun.Scenario])(nil) 14 15 const defaultSinkSize = 100 16 17 func NewProvider(fs afero.Fs, conf scenario.ProviderConfig) (core.Provider, error) { 18 const op = "scenario_grpc.NewProvider" 19 ammoCfg, err := config.ReadAmmoConfig(fs, conf.File) 20 if err != nil { 21 return nil, fmt.Errorf("%s ReadAmmoConfig %w", op, err) 22 } 23 vs, err := config.ExtractVariableStorage(ammoCfg) 24 if err != nil { 25 return nil, fmt.Errorf("%s buildVariableStorage %w", op, err) 26 } 27 28 ammos, err := decodeAmmo(ammoCfg, vs) 29 if err != nil { 30 return nil, fmt.Errorf("%s decodeAmmo %w", op, err) 31 } 32 33 p := &scenario.Provider[*gun.Scenario]{} 34 p.SetConfig(conf) 35 p.SetSink(make(chan *gun.Scenario, defaultSinkSize)) 36 p.SetAmmos(ammos) 37 38 return p, nil 39 }