Documentation ¶
Index ¶
- Constants
- Variables
- func NewCustomJSONProvider(wrapDecoder func(deps core.ProviderDeps, decoder AmmoDecoder) AmmoDecoder, ...) core.Provider
- func NewJSONProvider(newAmmo func() core.Ammo, conf JSONProviderConfig) core.Provider
- func NewNum(limit int) core.Provider
- func NewNumBuffered(limit int) core.Provider
- func NewNumConf(conf NumConfig) core.Provider
- type AmmoDecoder
- type AmmoDecoderFunc
- type AmmoQueue
- type AmmoQueueConfig
- type ChunkAmmoDecoder
- type DecodeProvider
- type DecodeProviderConfig
- type Dummy
- type JSONAmmoDecoder
- type JSONProviderConfig
- type NewAmmoDecoder
- type NumConfig
- type ScanAmmoDecoder
- type Scanner
Constants ¶
const (
DefaultAmmoQueueSize = shootsPerSecondUpperBound / 16
)
Variables ¶
var ErrNoAmmoDecoded = fmt.Errorf("no ammo has been decoded from chunk")
Functions ¶
func NewCustomJSONProvider ¶ added in v0.3.0
func NewCustomJSONProvider(wrapDecoder func(deps core.ProviderDeps, decoder AmmoDecoder) AmmoDecoder, newAmmo func() core.Ammo, conf JSONProviderConfig) core.Provider
NewCustomJSONProvider is like NewJSONProvider, but also allows to wrap JSON decoder, to decode data into intermediate struct, but then transform in into desired ammo. For example, decode {"body":"some data"} into struct { Data string }, and transform it to http.Request.
func NewJSONProvider ¶ added in v0.3.0
func NewJSONProvider(newAmmo func() core.Ammo, conf JSONProviderConfig) core.Provider
NewJSONProvider returns generic core.Provider that reads JSON data from source and decodes it into ammo returned from newAmmo.
func NewNum ¶
NewNum returns dummy provider, that provides 0, 1 .. n int sequence as ammo. May be useful for test or in when Gun don't need ammo.
func NewNumBuffered ¶ added in v0.4.0
func NewNumConf ¶
Types ¶
type AmmoDecoder ¶ added in v0.3.0
type AmmoDecoder interface { // Decode fills passed ammo with data. // Returns non nil error on fail. // Panics if ammo type is not supported. Decode(ammo core.Ammo) error }
AmmoEncoder MAY support only concrete type of ammo. AmmoDecoder SHOULD NOT be used after first decode fail.
func NewJSONAmmoDecoder ¶ added in v0.3.0
func NewJSONAmmoDecoder(r io.Reader, buffSize int) AmmoDecoder
type AmmoDecoderFunc ¶ added in v0.3.0
type AmmoQueue ¶ added in v0.3.0
func NewAmmoQueue ¶ added in v0.3.0
func NewAmmoQueue(newAmmo func() core.Ammo, conf AmmoQueueConfig) *AmmoQueue
type AmmoQueueConfig ¶ added in v0.3.0
type AmmoQueueConfig struct { // AmmoQueueSize is number maximum number of ready but not acquired ammo. // On queue overflow, ammo decode is stopped. AmmoQueueSize int `config:"ammo-queue-size" validate:"min=1"` }
func DefaultAmmoQueueConfig ¶ added in v0.3.0
func DefaultAmmoQueueConfig() AmmoQueueConfig
type ChunkAmmoDecoder ¶ added in v0.3.0
type ChunkAmmoDecoder interface { // DecodeChunk accepts chunk of data, than decode it to ammo or change ChunkAmmoDecoder internal // state. // Returns nil on when ammo was successfully decoded. // ErrNoAmmoDecoded MAY be returned, to indicate that chunk was accepted, but ammo were not // decoded. // Returns other non nil error, on chunk decode fail. // Panics if ammo type is not supported. DecodeChunk(chunk []byte, ammo core.Ammo) error }
ChunkAmmoDecoder accept data chunks that can contain encoded ammo or some meta information that changes ChunkAmmoDecoder state and affects next ammo decoding. For example, chunks are lines that contains HTTP URI to be transformed to http.Request or HTTP header to be added to next decoded http.Requests.
type DecodeProvider ¶ added in v0.3.0
type DecodeProvider struct { AmmoQueue core.ProviderDeps // contains filtered or unexported fields }
func NewDecodeProvider ¶ added in v0.3.0
func NewDecodeProvider(newAmmo func() core.Ammo, newDecoder NewAmmoDecoder, conf DecodeProviderConfig) *DecodeProvider
func (*DecodeProvider) Run ¶ added in v0.3.0
func (p *DecodeProvider) Run(ctx context.Context, deps core.ProviderDeps) (err error)
type DecodeProviderConfig ¶ added in v0.3.0
type DecodeProviderConfig struct { Queue AmmoQueueConfig `config:",squash"` Source core.DataSource `config:"source" validate:"required"` // Limit limits total num of ammo. Unlimited if zero. Limit int `validate:"min=0"` // Passes limits ammo file passes. Unlimited if zero. Passes int `validate:"min=0"` }
func DefaultDecodeProviderConfig ¶ added in v0.3.0
func DefaultDecodeProviderConfig() DecodeProviderConfig
type JSONAmmoDecoder ¶ added in v0.3.0
type JSONAmmoDecoder struct {
// contains filtered or unexported fields
}
type JSONProviderConfig ¶ added in v0.3.0
type JSONProviderConfig struct { Decode DecodeProviderConfig `config:",squash"` Buffer coreutil.BufferSizeConfig `config:",squash"` }
func DefaultJSONProviderConfig ¶ added in v0.3.0
func DefaultJSONProviderConfig() JSONProviderConfig
type NewAmmoDecoder ¶ added in v0.3.0
type NewAmmoDecoder func(deps core.ProviderDeps, source io.Reader) (AmmoDecoder, error)
type ScanAmmoDecoder ¶ added in v0.3.0
type ScanAmmoDecoder struct {
// contains filtered or unexported fields
}
func NewScanDecoder ¶ added in v0.3.0
func NewScanDecoder(scanner Scanner, decoder ChunkAmmoDecoder) *ScanAmmoDecoder