-
Notifications
You must be signed in to change notification settings - Fork 63
/
wrapper.go
50 lines (40 loc) · 1.25 KB
/
wrapper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package phttp
import (
"net/http"
"github.com/yandex/pandora/core"
"github.com/yandex/pandora/core/aggregator/netsample"
"github.com/yandex/pandora/core/warmup"
)
//go:generate mockery --name=Ammo --case=underscore --outpkg=ammomock
// Ammo ammo interface for http based guns.
// http ammo providers should produce ammo that implements Ammo.
// http guns should use convert ammo to Ammo, not to specific implementation.
// Returned request have
type Ammo interface {
// TODO(skipor): instead of sample use it wrapper with httptrace and more usable interface.
Request() (*http.Request, *netsample.Sample)
// Id unique ammo id. Usually equals to ammo num got from provider.
ID() uint64
IsInvalid() bool
}
type Gun interface {
Shoot(ammo Ammo)
Bind(sample netsample.Aggregator, deps core.GunDeps) error
WarmUp(opts *warmup.Options) (any, error)
}
func WrapGun(g Gun) core.Gun {
if g == nil {
return nil
}
return &gunWrapper{g}
}
type gunWrapper struct{ Gun }
func (g *gunWrapper) Shoot(ammo core.Ammo) {
g.Gun.Shoot(ammo.(Ammo))
}
func (g *gunWrapper) Bind(a core.Aggregator, deps core.GunDeps) error {
return g.Gun.Bind(netsample.UnwrapAggregator(a), deps)
}
func (g *gunWrapper) WarmUp(opts *warmup.Options) (any, error) {
return g.Gun.WarmUp(opts)
}