provider

package
v0.5.23 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 17, 2024 License: MPL-2.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

View Source
const (
	DefaultAmmoQueueSize = shootsPerSecondUpperBound / 16
)

Variables

View Source
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

func NewNum(limit int) core.Provider

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 NewNumBuffered(limit int) core.Provider

func NewNumConf

func NewNumConf(conf NumConfig) core.Provider

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 AmmoDecoderFunc func(ammo core.Ammo) error

func (AmmoDecoderFunc) Decode added in v0.3.0

func (f AmmoDecoderFunc) Decode(ammo core.Ammo) error

type AmmoQueue added in v0.3.0

type AmmoQueue struct {
	OutQueue  chan core.Ammo
	InputPool sync.Pool
}

func NewAmmoQueue added in v0.3.0

func NewAmmoQueue(newAmmo func() core.Ammo, conf AmmoQueueConfig) *AmmoQueue

func (*AmmoQueue) Acquire added in v0.3.0

func (p *AmmoQueue) Acquire() (core.Ammo, bool)

func (*AmmoQueue) Release added in v0.3.0

func (p *AmmoQueue) Release(a core.Ammo)

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 Dummy added in v0.5.8

type Dummy struct {
}

func (Dummy) Acquire added in v0.5.8

func (d Dummy) Acquire() (ammo core.Ammo, ok bool)

func (Dummy) Release added in v0.5.8

func (d Dummy) Release(core.Ammo)

func (Dummy) Run added in v0.5.8

type JSONAmmoDecoder added in v0.3.0

type JSONAmmoDecoder struct {
	// contains filtered or unexported fields
}

func (*JSONAmmoDecoder) Decode added in v0.3.0

func (d *JSONAmmoDecoder) Decode(ammo core.Ammo) error

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 NumConfig

type NumConfig struct {
	Limit int
}

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

func (*ScanAmmoDecoder) Decode added in v0.3.0

func (d *ScanAmmoDecoder) Decode(ammo core.Ammo) error

type Scanner added in v0.3.0

type Scanner interface {
	Scan() bool
	Bytes() []byte
	Err() error
}

Scanner is interface of bufio.Scanner like scanners.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL