converter

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: May 23, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package converter provides a framework for creating converters.

Index

Constants

View Source
const Type = "converter"

Type of the entity.

Variables

This section is empty.

Functions

This section is empty.

Types

type Converter

type Converter[T any] struct {
	// Description of the processor.
	Description string `json:"description"`

	// Logger is the pipeline logger.
	Logger sypl.ISypl `json:"-" validate:"required"`

	// Name of the stage.
	Name string `json:"name" validate:"required"`

	// OnFinished is the function that is called when a processor finishes its
	// execution.
	OnFinished OnFinished[T] `json:"-"`

	// Metrics.
	CounterCreated *expvar.Int    `json:"counterCreated" validate:"required,gte=0"`
	CounterRunning *expvar.Int    `json:"counterRunning" validate:"required,gte=0"`
	CounterFailed  *expvar.Int    `json:"counterFailed" validate:"required,gte=0"`
	CounterDone    *expvar.Int    `json:"counterDone" validate:"required,gte=0"`
	Status         *expvar.String `json:"status" validate:"required,gte=0"`
}

Converter definition.

func New

func New[T any](name, description string) (*Converter[T], error)

New returns a new stage.

func (*Converter[T]) GetCounterCreated

func (c *Converter[T]) GetCounterCreated() *expvar.Int

GetCounterCreated returns the `CounterCreated` of the processor.

func (*Converter[T]) GetCounterDone

func (c *Converter[T]) GetCounterDone() *expvar.Int

GetCounterDone returns the `CounterDone` of the processor.

func (*Converter[T]) GetCounterFailed

func (c *Converter[T]) GetCounterFailed() *expvar.Int

GetCounterFailed returns the `CounterFailed` of the processor.

func (*Converter[T]) GetCounterRunning

func (c *Converter[T]) GetCounterRunning() *expvar.Int

GetCounterRunning returns the `CounterRunning` of the processor.

func (*Converter[T]) GetDescription

func (c *Converter[T]) GetDescription() string

GetDescription returns the `Description` of the processor.

func (*Converter[T]) GetLogger

func (c *Converter[T]) GetLogger() sypl.ISypl

GetLogger returns the `Logger` of the processor.

func (*Converter[T]) GetName

func (c *Converter[T]) GetName() string

GetName returns the `Name` of the stage.

func (*Converter[T]) GetOnFinished

func (c *Converter[T]) GetOnFinished() OnFinished[T]

GetOnFinished returns the `OnFinished` function.

func (*Converter[T]) GetStatus

func (c *Converter[T]) GetStatus() *expvar.String

GetStatus returns the `Status` metric.

func (*Converter[T]) GetType

func (c *Converter[T]) GetType() string

GetType returns the entity type.

func (*Converter[T]) SetOnFinished

func (c *Converter[T]) SetOnFinished(onFinished OnFinished[T])

SetOnFinished sets the `OnFinished` function.

type Func

type Func[T any] func(p IConverter[T]) IConverter[T]

Func allows to specify message's options.

func WithOnFinished

func WithOnFinished[T any](onFinished OnFinished[T]) Func[T]

WithOnFinished sets the OnFinished function.

type IConverter

type IConverter[T any] interface {
	shared.IMeta

	shared.IMetrics

	// GetOnFinished returns the `OnFinished` function.
	GetOnFinished() OnFinished[T]

	// SetOnFinished sets the `OnFinished` function.
	SetOnFinished(onFinished OnFinished[T])

	// Run the converter function.
	Run(ctx context.Context, r io.Reader) (T, error)
}

IConverter defines what a `Conveter` must do.

type OnFinished

type OnFinished[T any] func(ctx context.Context, c IConverter[T], r io.Reader, processed []T)

OnFinished is the function that is called when a processor finishes its execution.

Jump to

Keyboard shortcuts

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